Message Boards Message Boards

0
|
1980 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Extracting a list from each nxn matrix from a set of matrices

Posted 1 year ago

I want to extract (Take command) row2 from each matrix (6x6) from a set consisting of 6 matrices. That is extracting row2 list.
This is the list of lists:

{{{0, 0, 2, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {-2, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 1, 0, 0}, {0, 0, 1, 0, 0, 0}, {0, -1, 0, 0, 0, 0}, {-1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {-1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0}, {0, 0, 0, 1, 0, 0}, {0, 0, -1, 0, 0, 0}, {0, -1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 2, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, -2, 0, 0, 0}, {0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, -1, 0, 0, 0, 0}, {0, 0, 0, 0,    0, 0}, {0, 0, 0, 0, 0, 0}}}

Using StructureConstantsList[[1,All]] results in the whole of 1st matrix (list form) instead of only row2 of that matrix.

I used the following commands and got the respective outputs:

StructureConstantsList[[1, ;;]]
StructureConstantsList[[ 1, All]]
Take[StructureConstantsList, 1]
Part[StructureConstantsList, 1]

Out[139]= {{0, 0, 2, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {-2, 0, 0, 0, 0,
  0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}

Out[140]= {{0, 0, 2, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {-2, 0, 0, 0, 0,
  0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}

Out[141]= {{{0, 0, 2, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {-2, 0, 0, 0, 0,
   0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}}

Out[142]= {{0, 0, 2, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {-2, 0, 0, 0, 0,
  0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}

How can I achieve extracting a row using # and one of the above commands?

Finally, I want to write using functional programming, n=6 (dimension ) , write for row1, row3, row4, ....
i (list of my symmetries): 1, ... , n.
k (list of matrices): 1, ... , n.

POSTED BY: Nomsa Ledwaba
5 Replies
Posted 1 year ago

To get the second row from each matrix, you can do this:

StructureConstantsList[[All, 2]]

I don't understand anything after "Finally"

POSTED BY: Eric Rimbey
Posted 1 year ago

Hello. Thank you for responding.

The command you suggested does not output the 2nd row. It outputs the whole 2nd row, a list (which it is a 6x6 matrix in MatrixForm) in a set of lists. I also used the following commands and got the same outputs:

StructureConstantsList[[2, ;;]]
StructureConstantsList[[ 2, All]]
Take[StructureConstantsList, 2]
Part[StructureConstantsList, 2]

May you please advise further.

POSTED BY: Nomsa Ledwaba
Posted 1 year ago
POSTED BY: Eric Rimbey
Posted 1 year ago

Hello. Yes, you are correct. It is exactly how I want to extract row2 from each list. It works! Thank you very much.

Now I want to write it in functional programming whereby I extract row2 from every list that is in the set of lists using # (to represent the number of lists I will be extracting from ). In this case, there are 6 lists in a set. Each list has 6 dimensions, as I already stated.

POSTED BY: Nomsa Ledwaba
Posted 1 year ago

Well, I suppose I could write that up, but you don't need to specify the number of sub-matrices in your argument. It will work for any number.

StructureConstantsList = ArrayReshape[PadRight[Alphabet[], 5 3^2, Alphabet[]], {5, 3, 3}];
StructureConstantsList[[All, 2]]
(* {{"d", "e", "f"}, {"m", "n", "o"}, {"v", "w", "x"}, {"e", "f", "g"}, {"n", "o", "p"}} *)

StructureConstantsList = ArrayReshape[PadRight[Alphabet[], 1 3^2, Alphabet[]], {1, 3, 3}];
StructureConstantsList[[All, 2]]
(* {{"d", "e", "f"}} *)

If what you want is a function that takes the lists of matrices as an argument, you can do that easily:

#[[All, 2]] &

Or are you saying that you want the index of the row to be an argument?

RowsByIndex[listOfMatrices_, index_] := listOfMatrices[[All, index]]
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract