在mathematica中使用嵌套数组和列表
这里绝对是初学者的问题。 我在数学中有两个列表。 第一个是由 Table 命令生成的:
Table[QP[[i]], {i, 10}]
它生成列表:
{52.5, 45., 37.5, 30., 22.5, 15., 7.5, 0., -7.5, -15.}
第二个是 Range
Range[ 0, 9, 1]
生成 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
我需要将这些放入列表列表中。即 {{0,52.5},{1,45} ... } 等。但我似乎无法理解。需要使用循环吗?因为我认为我想要的东西可以用 Table 和 Array 命令生成。
谢谢
Absolute beginner question here.
I have two lists in mathematica.
The first one was generated by the Table command:
Table[QP[[i]], {i, 10}]
which generates the list:
{52.5, 45., 37.5, 30., 22.5, 15., 7.5, 0., -7.5, -15.}
the second is a Range
Range[0, 9, 1]
which generates {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
I need to get these into a list of lists. i.e. {{0,52.5},{1,45} ... } etc. But I can't seem to get it. Do you need to use loops? Because I think that what I want can be generated with the Table and Array commands.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Transpose
可能是你想要的:给出
Transpose
may be what you want:gives
Table
的第一个参数可以是任何表达式。您可以通过指定列表作为第一个参数来让它输出列表的列表:The first parameter of
Table
can be any expression. You can have it output a list of lists, by specifying a list as the first parameter:要完成方法的阐述,您可以使用
MapIndexed
其中
或者,您可以使用
MapThread
虽然,
MapIndexed
更合适,因为它不需要您生成额外的列表。我想说的最后一点是,您的代码
Table[QP[[i]], {i, 10}]
意味着QP
本身是一个列表。 (双括号[[ ]]
泄露了它。)如果这是正确的,那么Table
不是生成子集的最佳方法,您可以使用部分
([[ ]]
< /a>) 和Span
直接或者
然后替换
data即可
在具有这些形式的代码的第一位中。To complete the exposition of methods, you could use
MapIndexed
where
Or, you could use
MapThread
Although,
MapIndexed
is more appropriate since it does not require you to generate an extra list.A last point I want to make is that your code
Table[QP[[i]], {i, 10}]
implies thatQP
itself is a list. (The double brackets,[[ ]]
, gave it away.) If that is correct, thanTable
isn't the best way to generate a subset, you can usePart
([[ ]]
) along withSpan
directlyor
Then, you can replace
data
in the first bits of code with either of those forms.