[Numpy-discussion] ndarray is not a sequence
Sturla Molden
sturla.molden at gmail.com
Fri Feb 28 03:47:26 EST 2014
Anthony Scopatz <scopatz at gmail.com> wrote:
> Hello All,
>
> The semantics of this seem quite insane to me:
>
> In [1]: import numpy as np
>
> In [2]: import collections
>
> In [4]: isinstance(np.arange(5), collections.Sequence) Out[4]: False
>
> In [6]: np.version.full_version
> Out[6]: '1.9.0.dev-eb40f65'
>
> Is there any possibility that ndarray could inherit (in the last place)
> from collections.Sequence? It seems like this would only be a 1 - 5 line
> fix somewhere. I just spent a few hours tracking down a bug related to
> this. Thanks for considering!
>
This should be very easy to do. But what would this give us, and what would
the extra overhead be? collections.Sequence is basically an abstract base
class. If this just slows down ndarray it would be highly undesirable. Note
that ndarray has a very specific use (numerical computing). If inheriting
collections.Sequence has no benefit for numerical computing it is just
wasteful overhead. In this resepect ndarray is very different for other
Python containers in that they have no specific use and computational
performance is not a big issue.
Sturla
More information about the NumPy-Discussion
mailing list