[英]How to go from Python numpy 3D array to 2D to 1D back to 2D (preserving the original 2nd and 3rd dimension of the 3D array)
[英]How to replace the first dimension of a 3D numpy array with values from a 1D array?
我有一个 3D 和一个 1D numpy 数组 - A 大小(3750、17、1000)和 B 大小(3750)。 我想用数组 B 中的值替换 A 的第一维中的值,以便结果数组 C 的大小仍然是 (3750, 17, 1000),但第一维中的值不同。
>>> A.shape
(3750, 17, 1000)
>>> B.shape (3750,)
>>> C.shape(3750, 17, 1000)
我试过了:
>>> C = np.concatenate((A, np.broadcast_to(np.array(B)[:, None, None],A.shape)), axis = 0)
但输出是:
>>> C.shape (7500, 17, 1000)
所以基本上如果
一 =
1 [x, y ... 1000]
[x, y ... 1000]
...17
2 [x, y ... 1000]
[x, y ... 1000]
...17
3 [x, y ... 1000]
[x, y ... 1000]
...17
.
.
.
3750
和 B =
22
43
11
.
.
n=3750
那么 C 应该看起来像
22 [x, y ... 1000]
[x, y ... 1000]
...17
43 [x, y ... 1000]
[x, y ... 1000]
...17
11 [x, y ... 1000]
[x, y ... 1000]
...17
.
.
.
n=3750
你的意思是:
A[:,0,0] = B
这是正确的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.