gpt4 book ai didi

python - 如何 reshape 3d numpy 表?

转载 作者:行者123 更新时间:2023-12-01 23:11:47 27 4
gpt4 key购买 nike

我有一个 shape=(2,3,4) 的 3d numpy 表,如下所示:

a = np.array([[[1., 2., 3., 4.],
[1., 2., 3., 4.],
[1., 2., 3., 4.]],

[[5., 6., 7., 8.],
[5., 6., 7., 8.],
[5., 6., 7., 8.]]])

并希望以每个维度中的列堆叠成二维矩阵中的新列的方式 reshape 它。

1  5
1 5
1 5
2 6
2 6
2 6
3 7
3 7
3 7
4 8
4 8
4 8

最佳答案

给你:

res = a.T.reshape((-1,2))

输出:

array([[1., 5.],
[1., 5.],
[1., 5.],
[2., 6.],
[2., 6.],
[2., 6.],
[3., 7.],
[3., 7.],
[3., 7.],
[4., 8.],
[4., 8.],
[4., 8.]])

关于python - 如何 reshape 3d numpy 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69759141/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com