[Numpy-discussion] question about creating numpy arrays

josef.pktd at gmail.com josef.pktd at gmail.com
Wed May 19 16:19:44 EDT 2010


On Wed, May 19, 2010 at 4:08 PM, Darren Dale <dsdale24 at gmail.com> wrote:
> 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?

These are "array_like" of floats, so why should it create anything
else than an array of floats.
It's the most common usecase

"array_like" is the most popular type for parameters in the docstrings

Josef

>
> Thanks,
> Darren
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list