gpt4 book ai didi

python - 我如何调用整数的 np.zeros?

转载 作者:太空狗 更新时间:2023-10-29 21:21:52 24 4
gpt4 key购买 nike

Musica = np.zeros((row*120,3))

for k in range(21, 90):
for i in range(row):
for j in range(Max[k], Min[k]):
Musica[i*120 + j,:] = 0,i,j
if np.all(data[i*col + j,:]==(255.000,0.000,0.000,i,j)):
Music[i*120 + j,:] = 1,i,j

Max[k]Min[k] 是属于数学整数组的数字,但我从 python 得到这条消息

"TypeError: range() integer end argument expected, got numpy.float64."

如何调用整数类型的np.zeros

现在我正在尝试使用以下代码:

Musica = np.zeros((row*120,3))

for k in range(21, 90):
for i in range(row):
Max = int(Max[k])
Min = int(Min[k])
for j in range(Max, Min):
Musica[i*120 + j,:] = 0,i,j
if np.all(data[i*col + j,:]==(255.000,0.000,0.000,i,j)):
Musica[i*120 + j,:] = 1,i,j

我收到的错误信息是:

Traceback (most recent call last):

File "<ipython-input-115-4aef2441146c>", line 1, in <module>
runfile('C:/Users/Arthur_USP/Desktop/Informação/Nova abordagem/untitled0.py', wdir='C:/Users/Arthur_USP/Desktop/Informação/Nova abordagem')

File "C:\Users\Arthur_USP\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)

File "C:\Users\Arthur_USP\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)

File "C:/Users/Arthur_USP/Desktop/Informação/Nova abordagem/untitled0.py", line 181, in <module>

TypeError: 'int' object has no attribute '__getitem__'

第 181 行是“Max = int(Max[k])”

最佳答案

你可以试试 np.zeros(shape).astype(int)

编辑:实际上,zeros 接受 dtype 参数。所以更好的是 np.zeros(shape, dtype=int)

关于python - 我如何调用整数的 np.zeros?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38318648/

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