[SciPy-User] creating a view of an array
mathieu lacage
mathieu.lacage at alcmeon.com
Sun Jul 31 02:53:59 EDT 2011
On Sun, Jul 31, 2011 at 12:02 AM, Joe Kington <jkington at wisc.edu> wrote:
>
> a[:,(0,2)]
>>
>
Indeed. It "just" creates a copy :/
>
>> That way you can index into any columns.
>>
> You can index using a tuple too, like:
>
> Just to clarify:
>
> Using a list or tuple for indexing is "fancy" indexing and returns a copy,
> not a view.
>
yes.
>
> I believe the OP was specifically wanting a view. (And I don't think it's
> directly possible, though you can write a simple wrapper class to do it.)
>
With some creative use of index offsets, I came up with the following for
two arbitrary columns in an array:
# create big array
a = numpy.empty((10000000,10))
# extract columns 2 and 4 (no copy !)
b = a[::,2:5:2]
This trick will obviously not work for three columns unless they are equally
spaced. So, I wonder if there are other tricks I could use to build an array
where the stride is irregular (say, extract columns 2, 4, and 5 from the
above array without creating a copy)
Mathieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110731/8c17ffe5/attachment.html>
More information about the SciPy-User
mailing list