numpy附加2D数组

发布于 2025-02-09 17:15:34 字数 233 浏览 2 评论 0原文

假设我有一堆2D数组形状(32,32)我想与较大的3D阵列分开。

我不知道有多少个2D阵列,所以必须附加它们。

我尝试过堆叠,但这仅适用于前两个阵列。

我想要的是拥有一大批形状(0,32,32),当我附加时,第一个2D数组将变成(1,32,32)然后(2,32,32),但到目前为止对我来说还没有任何作用。

Let's say I have a bunch of 2d arrays shape (32,32) that I want to be apart of a larger 3d array.

I don't know how many 2d arrays there are so they must be appended.

I've tried stacking but that only works for the first 2 arrays.

What I want is to have a big array of shape (0, 32, 32) that when I append the first 2d array will become (1, 32, 32) then (2, 32, 32) but so far nothing has worked for me.

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

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

发布评论

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

评论(1

三生一梦 2025-02-16 17:15:35

您可以尝试将2D数组重塑为3D数组,并在轴0中具有一个维度:

big_array = np.zeros((1,32,32))

2d_array = np.ones((32,32))

big_array = np.append(big_array, 2d_array.reshape(1,32,32), axis=0)
big_array.shape
>>> (2,32,32)

You can try reshaping the 2d arrays into 3d arrays with one dimension in the axis 0:

big_array = np.zeros((1,32,32))

2d_array = np.ones((32,32))

big_array = np.append(big_array, 2d_array.reshape(1,32,32), axis=0)
big_array.shape
>>> (2,32,32)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文