import numpy as np
# an example array with shape [2,3,4]
a = np.random.random([2,3,4])
# create the target array shaped [2,3] with 'object' type (accepting other types than numbers).
b = np.array([[None for row in mat] for mat in a])
for i in range(b.shape[0]):
for j in range(b.shape[1]):
b[i,j] = list(a[i,j])
我无法想象为什么numpy会需要这样的方法。这是,或多或少,一个肾盂解决方案。你知道吗
您可以使用
tolist
并指定给预分配的对象数组:相关问题 更多 >
编程相关推荐