Maxima:将矩阵转换为列表

发布于 2024-12-23 09:10:25 字数 194 浏览 8 评论 0 原文

我通过以下方式将 Maxima 中的列表转换为矩阵:

DataL : [ [1,2], [2,4], [3,6], [4,8] ];
DataM: apply('matrix,DataL);

如何以其他方式进行操作?如何将给定矩阵 DataM 转换为列表 DataL

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难如初 2024-12-30 09:10:25

我知道现在已经很晚了,但就其价值而言,还有一种更简单的方法。

my_matrix : matrix ([a, b, c], [d, e, f]);
my_list : args (my_matrix);
 => [[a, b, c], [d, e, f]]

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]]
永言不败 2024-12-30 09:10:25

我距离 Maxima 专家还很远,但是自从 你让我看看这个问题,这是我快速浏览文档

首先,查看矩阵文档只得到了一种转向方法矩阵放入列表中,即list_matrix_entries。但是,这会返回一个简单的条目列表。要获得嵌套列表结构,可以使用如下所示的方法,

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  */

这很笨拙,而且可能效率低下。使用 Maxima 中的底层 Lisp 结构(以及与我更熟悉的 Mathematica 的类比),您可以使用 part

part(DataL, 0);  /*  [       */
part(DataM, 0);  /*  matrix  */

然后要在两个结构之间进行转换,您可以使用 substpart

is(substpart(matrix, DataL, 0) = DataM);   /*  true  */
is(substpart( "[",   DataM, 0) = DataL);   /*  true  */

substpart >0 与使用 apply,但它不仅仅适用于列表。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文