我想在 python 中制作一个 4 维零数组。 我知道如何为方形数组执行此操作,但我希望列表具有不同的长度。
现在我用这个:
numpy.zeros((200,)*4)
它们的长度均为 200,但我希望长度为 200,20,100,20
,因为现在我的数组中有很多我不使用的零
最佳答案
你可以使用np.full
:
>>> np.full((200,20,10,20), 0)
numpy.full
Return a new array of given shape and type, filled with fill_value.
示例:
>>> np.full((1,3,2,4), 0)
array([[[[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]],
[[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]],
[[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]]]])
关于python - python 中的 4 维零数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29921407/