[SciPy-dev] Nested arrays

Sasha ndarray at mac.com
Tue Jan 10 15:25:07 CST 2006


"Always being able to get the .shape attribute" is a nice feature and
I would rather
not loose it without a compelling reason.  Note that making ndarray a
valid dtype
will not have an effect of a[i] loosing array API because ndarrays
already have it by
definition.  For objects that don't have their own array interface one
can entertain an
idea of creating a scalar class dynamically that inherits from the
type of the object and
mixes in array API using muliple inheritance or some metaclass magic.

Making ndarray a valid dtype will also allow constructing arrays from
ragged lists

array([[1],[1,2,3]], ndarray) -> array([array([1]), array([1,2,3])],
dtype=ndarray)

Currently this construct is equivalent to array([[1],[1,2,3]],object)
and returns a strange result:

>>> array([[1],[1,2,3]],ndarray)
array([[1, 1, 1],
       [1, 2, 3]], dtype=object)
>>> array([[1],[1,2,3]],ndarray).shape
(2, 3)

Interestingly,
>>> array([[1,2],[1,2,3]],ndarray).shape
()

-- sasha

On 1/10/06, Robert Kern <robert.kern at gmail.com> wrote:
> ...
> I think we should reconsider the decision to return scalar array objects when
> indexing into object arrays. The concerns for indexing into numeric arrays are
> much different than for object arrays. There are no type casting issues with
> object arrays. People use object arrays expecting to be able to access the
> objects themselves, not some proxy. I'm not sure that the genericity benefits
> (e.g. always being able to get the .shape attribute) one gets with scalar arrays
> carry over very well to the use cases of object arrays. Object arrays have
> always really been a collection of special cases, so I'm not terribly concerned
> about giving them exceptional behavior.
>
> --
> Robert Kern
> robert.kern at gmail.com
>
> "In the fields of hell where the grass grows high
>  Are the graves of dreams allowed to die."
>   -- Richard Harter
>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-dev
>




More information about the Scipy-dev mailing list