Mathematica 表格集
我有三个表X,Y,Z
。而X
& Y
定义我的网格点,Z
取决于 X
和 Y
的每个点。
x = Table[i, {i, 0, 10, 1}]
y = Table[j, {j, 0, 10, 1}]
z = Table[5*i + j, {i, 0, 10, 1}, {j, 0, 10, 1}]
现在我希望最终列表看起来像这样 [{x1,y1,z1},{x2,y2,z2}}
我想创建一组相应的 x,y,z
上面给出的表中的值。
I have three tables X,Y,Z
. While X
& Y
define my grid points the Z
depends on every point of X
and Y
.
x = Table[i, {i, 0, 10, 1}]
y = Table[j, {j, 0, 10, 1}]
z = Table[5*i + j, {i, 0, 10, 1}, {j, 0, 10, 1}]
Now I want the final list to look like this [{x1,y1,z1},{x2,y2,z2}}
I want to create a set of corresponding x,y,z
values from the table given above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,您还可以使用
Array
如下:参见
Function
和插槽
。 rcollyer 已经展示了如何从中“拆分”x、y 和 z。当从不相关的列表
x
和y
开始时,您可以使用外部
:In this case you can also produce your combined list with
Array
as follows:See
Function
andSlot
. rcollyer has already shown how to "split out" x, y, and z from this.When starting with unrelated lists
x
andy
you can produce the combined list withOuter
:除非您需要
x
和y
列表,否则我会将其组合在一个Table
中,如下所示:注意,我删除了步长(
{i, 0, 10, 1}
->{i, 0, 10}
),因为如果不包含它,它会隐式设置为 1。编辑:如果您还希望拥有
x
和y
列表,您可以执行以下操作从 v.7 开始,
Table
除了起点和终点之外还接受值列表。这并没有解决您是否还需要单独的z
列表。在这种情况下,我将从第一个形式的代码开始,并使用Transpose
(根据您的其他 问题)设置各个列表,如下所示:Unless you need the the
x
andy
lists, I'd combine this in oneTable
as follows:Note, I removed the step length (
{i, 0, 10, 1}
->{i, 0, 10}
) as it's implicitly set to 1 if it is not included.Edit: If you wish to have the
x
andy
lists, also, you could do the followingAs of v.7,
Table
accepts lists of values in addition to start and end points. This doesn't address whether you need a separate list forz
, also. In that case, I'd start with the first form bit of code, and usingTranspose
(per your other question) to set the individual lists, as follows:从你开始的一种方法
是
(我很乐意看到我在一周内尝试理解这一点),它给出了你想要的东西。
这也有效:
并给出相同的答案。
One way to do it starting from your
is
(I'd love to see me try to understand this in a week) which gives what you want.
This also works:
and gives the same answer.