Double AA
Double AA

Reputation: 5989

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 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'

Upvotes: 1

Views: 2372

Answers (2)

senderle
senderle

Reputation: 151147

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]])

Upvotes: 3

Mark
Mark

Reputation: 798

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.

Upvotes: 4

Related Questions