我有一个 3Dnumpy数组,我想在它的前面添加一个 0 的 2D np 数组。
import numpy as np
A = np.zeros(3,3,3)
for i in np.arange(0,2):
for j in np.arange(0,2):
for k in np.arange(0,2):
A[i,j,k] = 10
print(A)
#returns:
[[[10. 10. 0.]
[10. 10. 0.]
[ 0. 0. 0.]]
[[10. 10. 0.]
[10. 10. 0.]
[ 0. 0. 0.]]
[[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]]]
我想添加另一个数组 B 以便:
B = np.zeros(3,3)
print(B)
#returns
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
# add B to front of A
# B + A =
[[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
[[10. 10. 0.]
[10. 10. 0.]
[ 0. 0. 0.]]
[[10. 10. 0.]
[10. 10. 0.]
[ 0. 0. 0.]]
[[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]]]
我试过 np.append(B,A) 但它返回一个二维数组。
ibeautiful
相关分类