开发者

Organizing an array of points in python

I need to input 3, 3D points as a matrix into this function; so I made a tuple like this one:

initPoints = ([10,20,30],[5,15,25],[100,150,200])

but I got the following error:

AttributeError: 'tuple' object has no开发者_如何学Go attribute 'shape'

The same thing happened when i used a list. any ideas? what is 'shape'? do i need some other kind of array? How can I do that? Thanks

Edit - the function I'm using is scipy.cluster.vq.kmeans2 with minit='matrix'


Perhaps the function is expecting a numpy array or matrix instead of a tuple of lists?

http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html http://docs.scipy.org/doc/numpy/reference/generated/numpy.matrix.html

>>> import numpy
>>> a = numpy.array(((1,2,3),(4,5,6)))
>>> a.shape
(2, 3)

We'd need more information (like what you are passing this to) to know for sure.


As the docs to scipy.cluster.vq.kmeans2 indicate, k should be a numpy.ndarray when you pass in minit='matrix'. So do this:

initPoints = numpy.array([[10,20,30],[5,15,25],[100,150,200]])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜