numpy数组除法-/:'list'和'float'不支持的操作数类型 [英] Numpy Array Division - unsupported operand type(s) for /: 'list' and 'float'
本文介绍了numpy数组除法-/:'list'和'float'不支持的操作数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义了以下numpy数组:
I defined the following numpy array:
import numpy as np
numpy_array = np.array([[-1,-1,-1,-1,-1], [-1,2,2,2,-1], [-1,2,8,2,-1], [-1,2,2,2,-1], [-1,-1,-1,-1,-1,-1]])
现在我想将整个数组除以8:
Now I wanted to divide the whole array by 8:
numpy_array /= np.float(8.0)
我收到以下错误消息:
TypeError: unsupported operand type(s) for /: 'list' and 'float'
我希望有人对我有提示,我在做错什么.
I hope someone has a hint for me, what I am doing wrong.
推荐答案
该数组的列表大小不正确,最终列表不正确.
The array has a list of the incorrect size, the final list is incorrect.
如果要将数据保留为int
,则可以使用numpy_array = np.divide(numpy_array, 8.0)
,否则请参见MSeifert的答案.
if you want to keep the data as an int
, you can use numpy_array = np.divide(numpy_array, 8.0)
, otherwise see MSeifert's answer.
这篇关于numpy数组除法-/:'list'和'float'不支持的操作数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文