The closest thing to what you want is to use recarray
instead of ndarray
Python objects:
num_stars = 10 dtype = numpy.dtype([('x', float), ('y', float), ('colour', float)]) a = numpy.recarray(num_stars, dtype=dtype) a.colour = numpy.arange(num_stars) print a.colour
prints
[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]
Using a NumPy array of Python objects is usually less efficient than using a simple list
, and recarray
stores data in a more efficient format.
source share