[Numpy-discussion] numpy.array does not take generators
Geoffrey Zhu
zyzhu2000@gmail....
Thu Aug 16 20:26:34 CDT 2007
Hi All,
I want to construct a numpy array based on Python objects. In the
below code, opts is a list of tuples.
For example,
opts=[ ('C', 100, 3, 'A'), ('K', 200, 5.4, 'B')]
If I use a generator like the following:
K=numpy.array(o[2]/1000.0 for o in opts)
It does not work.
I have to use:
numpy.array([o[2]/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?
Thanks,
Geoffrey
More information about the Numpy-discussion
mailing list