Group Abstract Group Abstract

Message Boards Message Boards

1
|
7.9K Views
|
6 Replies
|
11 Total Likes
View groups...
Share
Share this post:
GROUPS:

How to avoid the nested list in the command table?

Posted 11 years ago
6 Replies

How about using Tuples:

Tuples[{1, 2}, 4] // MatrixForm
POSTED BY: Kay Herbert
Posted 11 years ago

You can "unnest" it using Flatten:

Table[{{i, j, k, l}}, {i, 1, 2}, {j, 1, 2}, {k, 1, 2}, {l, 1, 2}] ~Flatten~ 4 // MatrixForm

Output

POSTED BY: Karsten 7.

This is a job for ArrayReshape

r = Table[{i, j, k, L0},
  {i, 1, 2},
  {j, 1, 2},
  {k, 1, 2},
  {L0, 1, 2}]
  (ArrayReshape[r, {16, 4}]) // MatrixForm

enter image description here

ps. in this specific case, as was mentioned above, Tuples[{1, 2}, 4] will do the same and much easier.

POSTED BY: Nasser M. Abbasi
Posted 11 years ago
linearvectors = KroneckerProduct @@@ (misure[[#]] & /@ Tuples[{1, 2}, 4])
POSTED BY: Kuba Podkalicki

Thank you all guys, at this moment I have done in this way:

Table[KroneckerProduct[misure[[i]], misure[[j]], misure[[k]], 
   misure[[l]]], {i, 1, 2}, {j, 1, 2}, {k, 1, 2}, {l, 1, 2}];
Flatten[%];
linearvectors = ArrayReshape[%, {16, 1, 16}];

Is there any way to put all those commands in one line? (I'm sorry for those idiot questions, this is my second day using mathematica and I had no time to read a manual :( )

Posted 11 years ago

just to show different approach:

table // Cases[#, _?VectorQ, {-2}] &
POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard