python中的3个多维阵列

发布于 2025-02-11 05:34:29 字数 884 浏览 1 评论 0原文

我有三个数组i1,i2,i3,带有Shape (1,9,2)。我正在尝试附加,但是有一个错误。新数组应具有形状(3,9,2)

import numpy as np

I1 = np.array([[[0, 2],
        [2, 3],
        [2, 5],
        [3, 4],
        [3, 6],
        [4, 1],
        [4, 7],
        [5, 6],
        [6, 7]]])

I2 = np.array([[[1, 1],
        [2, 3],
        [2, 5],
        [3, 4],
        [3, 6],
        [4, 1],
        [4, 7],
        [5, 6],
        [6, 7]]])

I3 = np.array([[[2, 2],
        [2, 3],
        [2, 5],
        [3, 4],
        [3, 6],
        [4, 1],
        [4, 7],
        [5, 6],
        [6, 7]]])

I=np.append(I1,I2,I3,axis=0)

错误是

in <module>
    Iit=np.append(Iit1,Iit2,Iit3,axis=0)

  File "<__array_function__ internals>", line 4, in append

TypeError: _append_dispatcher() got multiple values for argument 'axis'

I have three arrays I1,I2,I3 with shape (1,9,2). I am trying to append but there is an error. The new array should have shape (3,9,2)

import numpy as np

I1 = np.array([[[0, 2],
        [2, 3],
        [2, 5],
        [3, 4],
        [3, 6],
        [4, 1],
        [4, 7],
        [5, 6],
        [6, 7]]])

I2 = np.array([[[1, 1],
        [2, 3],
        [2, 5],
        [3, 4],
        [3, 6],
        [4, 1],
        [4, 7],
        [5, 6],
        [6, 7]]])

I3 = np.array([[[2, 2],
        [2, 3],
        [2, 5],
        [3, 4],
        [3, 6],
        [4, 1],
        [4, 7],
        [5, 6],
        [6, 7]]])

I=np.append(I1,I2,I3,axis=0)

The error is

in <module>
    Iit=np.append(Iit1,Iit2,Iit3,axis=0)

  File "<__array_function__ internals>", line 4, in append

TypeError: _append_dispatcher() got multiple values for argument 'axis'

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

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

发布评论

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

评论(2

っ〆星空下的拥抱 2025-02-18 05:34:29

使用i = np.concatenate([I1,I2,I3],axis = 0)而不是附加。 Append可以从列表中获得您期望的(并且出于内存分配原因,尽量不要在Numpy中使用它!)``)``

Use I=np.concatenate([I1,I2,I3],axis=0) rather than append. Append does what you'd expect from a list (and try not to use it in numpy, anyway, for memory allocation reasons!)`

就此别过 2025-02-18 05:34:29

与@dominik的另一种方法是

I = np.stack((I1,I2,I3))

stack 创建一个新的Axis 。

A different way from @Dominik is

I = np.stack((I1,I2,I3))

stack creates a new axis.

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