If I have a list that contains 16 sublist (enclosed in 2 curly

  • Thread starter Thread starter Sarah rob
  • Start date Start date
  • Tags Tags
    List
Click For Summary

Discussion Overview

The discussion revolves around manipulating a list containing 16 sublists in a programming context, specifically focusing on how to create new lists from existing sublists based on their indices. The scope includes technical reasoning and programming techniques.

Discussion Character

  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant presents a list L1 containing 16 sublists and seeks to create two new lists from specific sublists based on their indices.
  • Another participant questions the structure of L1, suggesting it may represent a 3-dimensional matrix and asks for clarification on the actual contents of the sublists.
  • A participant introduces the Part operator [[]] as a method to extract specific sublists from L1.
  • Further clarification is provided by the original poster, specifying the contents of the sublists and reiterating the goal of creating two new lists from selected sublists.
  • Another participant notes that the approach to creating new lists is contingent on the length of L1 being a multiple of 8 and provides a code snippet demonstrating how to extract the desired sublists using indexing.

Areas of Agreement / Disagreement

Participants express varying levels of understanding regarding the structure of L1 and the methods to extract sublists. There is no consensus on the best approach, as different methods and interpretations are proposed.

Contextual Notes

There are assumptions regarding the dimensionality of the list and the presence of specific elements within the sublists that remain unresolved. The discussion also hinges on the condition that the length of L1 must be a multiple of 8 for certain proposed methods to work.

Sarah rob
Messages
16
Reaction score
0
If I have a list that contains 16 sublist (enclosed in 2 curly bracets),
L1 = {{{1, 1}, {1, 5}, {1, 8}}, {{2, 6}, {1, 10}, {0, 12}},
{{3, 2}, {1, 4}, {0, 15}}, {{1, 8}, {1, 14}, {2, 17}},
{{1, 2}, {2, 8}, {3, 12}}, {{2, 6}, {2, 11}, {2, 18}},
{{3, 6}, {1, 9}, {2,17}}, {{1, 8}, {3, 18}, {2, 19}} ... ...};

could I create a list from L1 that is made up of sublist 1, 2, 3, 4, 9, 10, 11,
12 and another that is made up of sublist 5, 6, 7, 8, 13, 14, 15, 16

I have had the idea of using Mod but don' t quite know how to
constuct it:

sub = 0;
sub++;
If[Mod[sub, 8, 1] < 4, Map[something?, L1], Map[something?,L1]]
 
Physics news on Phys.org


With the nested {} in your L1 it seems that you have a 3 dimensional "matrix." Is that what you really have? Or do you have some extra {} that are not really in your data?

If all those {} are actually present then is sublist 1 = {1, 1} or is it {{1, 1}, {1, 5}, {1, 8}}?

Perhaps showing what L2 and L3 should have as values given your L1 would be the most precise way of describing what you need.

If you can answer those questions then it will be possible to show you ways to do what you want.
 


The Part operator [[]] can take a list as an argument. E.g.

L1[[{1, 2, 3, 4, 9, 10, 11, 12}]]
 


Sorry, didn't make it very clear

sublist 1 = {{1, 1}, {1, 5}, {1, 8}}
sublist 2 = {{2, 6}, {1, 10}, {0, 12}} ...

so I want a new list that will be {sublist 1,sublist 2,sublist 3,sublist 4,sublist 9,sublist 10, sublist 11,sublist 12}
And another {sublist 5,sublist 6,sublist 7,sublist 8,sublist 13,sublist 14, sublist 15,sublist 16}
 


As long as Length[L1] is a multiple of 8

In[1]:=L1={{{1,1},{1,5},{1,8}},{{2,6},{1,10},{0,12}},{{3,2},{1,4},{0,15}},{{1,8},{1,14},{2,17}},
{{1,2},{2,8},{3,12}},{{2,6},{2,11},{2,18}},{{3,6},{1,9},{2,17}},{{1,8},{3,18},{2,19}}};

In[2]:=L2=L1[[Flatten[Table[8j+i,{j,0,(Length[L1]-8)/8},{i,1,4}]]]]

In[3]:=L3=L1[[Flatten[Table[8j+i+4,{j,0,(Length[L1]-8)/8},{i,1,4}]]]]
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K