[Numpy-discussion] basearray / arraykit

Travis Oliphant oliphant.travis at ieee.org
Wed May 10 13:58:08 EDT 2006


Sasha wrote:
> On 5/10/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
>> ...
>> I'm thinking that fancy-indexing should be re-factored a bit so that
>> view-based indexing is tried first and then on error, fancy-indexing is
>> tried.   Right now, it goes through the fancy-indexing check and that
>> seems to slow things down more than it needs to for simple indexing
>> operations.
>
> Is it too late to reconsider the decision to further overload [] to
> support fancy indexing?   It would be nice to restrict [] to view
> based indexing and require a function call for copy-based.  If that is
> not an option, I would like to propose to have no __getitem__ in the
> basearray and instead have rich collection of various functions such
> as "take" which can be used by the derived classes to create their own
> __getitem__ .

It may be too late since the fancy-indexing was actually introduced by 
numarray.   It does seem to be a feature that people like.
>
> Independent of the fate of the [] operator, I would like to have means
> to specify exactly what I want without having to rely on the smartness
> of the fancy-indexing check.  For example, in the current version, I
> can either do x[[1,2,3]] or x.take([1,2,3]).  For a 2d x I can do
> x.take([1,2,3], axis=1) as an alternative to x[:,[1,2,3]], but I
> cannot find an equivalent of x[[3,2,1],[1,2,3]].
It probably isn't there.  Perhaps it should be.    As you've guessed, a 
lot of the overloading of [] is because inside it you can use simplified 
syntax to generate slices.    I would like to see the slice syntax 
extended so it could be used inside function calls as well as a means to 
generate slice objects on-the-fly.  Perhaps for Python 3.0 this could be 
suggested. 


-Travis





More information about the NumPy-Discussion mailing list