gpt4 book ai didi

python - python 中的 4 维零数组

转载 作者:太空狗 更新时间:2023-10-29 20:18:31 25 4
gpt4 key购买 nike

我想在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com