gpt4 book ai didi

python - 类型错误 : 'tuple' object cannot be interpreted as an integer

转载 作者:太空狗 更新时间:2023-10-30 01:45:32 25 4
gpt4 key购买 nike

我有 x0,它是一个 float64 (64,64) 数组。每当我尝试这个时:

    delta = np.random.randn(x0.shape)

它给出了标题错误。这是非常基本的,以至于我全神贯注。我错过了什么?谢谢

完整回溯如下:

Traceback (most recent call last):

File "<ipython-input-31-dcd2365ed519>", line 1, in <module>
delta = np.random.randn(x0.shape)

File "mtrand.pyx", line 1420, in mtrand.RandomState.randn

File "mtrand.pyx", line 1550, in mtrand.RandomState.standard_normal

File "mtrand.pyx", line 167, in mtrand.cont0_array

TypeError: 'tuple' object cannot be interpreted as an integer

最佳答案

np.random.randn() 需要整数参数,格式为 randn(64,64)。您以 randn((64,64)) 的形式提供 np.random.randn() 参数,这是它不期望的。相反,如果您想构建一个 64x64 随机数组,则需要单独传递行数和列数,而不是作为元组传递。

关于python - 类型错误 : 'tuple' object cannot be interpreted as an integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51088335/

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