Help with Python Grammar change
Timothy Docker
timd at macquarie.com.au
Tue Feb 15 17:46:54 EST 2000
Travis Oliphant <olipt at mayo.edu> writes:
> If a is a 3-dimensional array currently
>
> a[:,:,5] returns a reference to a two-dimensional sub-array.
>
> It would be useful if a(:,:,5) returned a copy to that array. Using the
> current grammar we could make a(slice(None),slice(None),5) return the
> copy, but it is definitely not as clever.
You could have a subobject in a with a __getindex__ method, that does
the copy, as opposed to the __getindex__ method in a, that returns the
reference, ie
a[:,:,5] returns a reference to a two-dimensional sub-array.
a.copy[:,:,5] returns a copy of that array.
Tim
More information about the Python-list
mailing list