I convert list to matrix in Maxima in following way:
DataL : [ [1,2], [2,4], [3,6], [4,8] ];
DataM: apply('matrix,DataL);
How to do it the other way ? How to convert given matrix DataM into list DataL ?
I know it's late in the game, but for what it's worth, there is a simpler way.
my_matrix : matrix ([a, b, c], [d, e, f]);
my_list : args (my_matrix);
=> [[a, b, c], [d, e, f]]
I'm far from a Maxima expert, but since you asked me to look at this question, here's what I have after a quick look through the documentation.
First, looking at the documentation on matrices yielded only one way of turning matrices in to lists, which is list_matrix_entries
. However, this returns a flat list of the entries. To get a nested list structure, something like the following works
DataL : [[1, 2], [2, 4], [3, 6], [4, 8]]; /* Using your example list */
DataM : apply('matrix, DataL); /* and matrix */
DataML : makelist(list_matrix_entries(row(DataM, i)), i, 1, 4);
is(DataML = DataL); /* true */
This is clumsy and probably inefficient. Using the underlying Lisp structure in Maxima (and analogy to Mathematica, which I'm more familiar with) you can examine the heads of DataL
and DataM
using part:
part(DataL, 0); /* [ */
part(DataM, 0); /* matrix */
Then to convert between the two structures, you can use substpart
is(substpart(matrix, DataL, 0) = DataM); /* true */
is(substpart( "[", DataM, 0) = DataL); /* true */
Using substpart
at level 0
is almost the same as using apply
, except it works on more than just lists.
来源:https://stackoverflow.com/questions/8688906/maxima-convert-matrix-to-list