[英]TypeError: 'float' object is not subscriptable in matrix
I have this error: 我有这个错误:
"TypeError: 'float' object is not subscriptable"
“ TypeError:“浮动”对象不可下标”
This is the part of the code that displays the error: 这是显示错误的代码部分:
nd_coord = random.uniform(npoints, 2)
nd_coord[:,0] = nd_coord[:,0] * ((xmax - xmin) + xmin)
nd_coord[:,1] = nd_coord[:,1] * ((ymax - ymin) + ymin)
print (nd_coord)
I take it you've imported NumPy as from numpy import *
and so random.uniform
is the NumPy method. 我认为您已经
from numpy import *
导入了NumPy,所以random.uniform
是NumPy方法。 Its call signature is: 其呼叫签名为:
numpy.random.uniform(low=0.0, high=1.0, size=None)
numpy.random.uniform(low = 0.0,high = 1.0,size = None)
So the way you're using it, it returns a single number (which can't be indexed). 因此,您使用它的方式将返回一个数字(无法编制索引)。 Perhaps you want:
也许您想要:
nd_coord = np.random.uniform(size=(npoints,2))
To pick npoints
pairs of random numbers on [0,1). 挑
npoints
在[0,1随机数对)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.