[Numpy-discussion] question about creating numpy arrays

Darren Dale dsdale24 at gmail.com
Wed May 19 16:08:57 EDT 2010


I have a question about creation of numpy arrays from a list of
objects, which bears on the Quantities project and also on masked
arrays:

>>> import quantities as pq
>>> import numpy as np
>>> a, b = 2*pq.m,1*pq.s
>>> np.array([a, b])
array([ 12.,   1.])

Why doesn't that create an object array? Similarly:

>>> m = np.ma.array([1], mask=[True])
>>> m
masked_array(data = [--],
             mask = [ True],
       fill_value = 999999)

>>> np.array([m])
array([[1]])

This has broader implications than just creating arrays, for example:

>>> np.sum([m, m])
2
>>> np.sum([a, b])
13.0

Any thoughts?

Thanks,
Darren



More information about the NumPy-Discussion mailing list