Home > Blockchain >  How to turn a table or matrix into a (flat) list in J
How to turn a table or matrix into a (flat) list in J

Time:12-29

I know how to reshape a list into a table. But how do I turn a table into a list or uni- dimensional array.

my_list=:3 4 $i.12

0 1  2  3
4 5  6  7
8 9 10 11

And is it better to perform operations on lists or tables or is there no difference (in terms of performance)

CodePudding user response:

, y (ravel) is what you need:

    , my_list
0 1 2 3 4 5 6 7 8 9 10 11

There is no performance difference for operations where the shape of the data does not matter, f.e. 1 my_list and 1 , my_list. Also reshaping is free (if no padding is involved), because internally the atoms are always saved as a flat list with its corresponding shape. my_list could be understood as the tuple of the lists data: 0…11 and shape: 3 4, while , my_list would be data: 0…11 and shape: 12.

  • Related