[Numpy-discussion] numpy.array does not take generators
zyzhu2000 at gmail.com
Thu Aug 16 21:26:34 EDT 2007
I want to construct a numpy array based on Python objects. In the
below code, opts is a list of tuples.
opts=[ ('C', 100, 3, 'A'), ('K', 200, 5.4, 'B')]
If I use a generator like the following:
K=numpy.array(o/1000.0 for o in opts)
It does not work.
I have to use:
numpy.array([o/1000.0 for o in opts])
Is this behavior intended?
By the way, it is quite inefficient to create numpy array this way,
because I have to create a regular python first, and then construct a
numpy array. But I do not want to store everything in vector form
initially, as it is more natural to store them in objects, and easier
to use when organizing the data. Does anyone know any better way?
More information about the NumPy-Discussion