如何在numpy中为循环嵌套的3d数组efter中打印值。
import numpy as np
center = 5
dim = 2
Bgr = 4
x = np.ones(dim)
y = np.zeros(dim)
z = np.ones(dim)
A =np.array(np.ones((dim,dim,dim)))*Bgr
for i in x:
for j in y:
for k in z:
print(A([[i],[j],[k]]))
TypeError:“ numpy.ndarray”对象不可调用
答案 0 :(得分:0)
您可以使用len(np_array)
或np_array.shape[0]
来获得编号。行,然后进行迭代
for i in range (len(x)):
for j in range(len(y)):
for k in range(len(z)):
print(A[i][j][k])