[Numpy-discussion] Striding on NumArray objects
Tim Hochberg
tim.hochberg at cox.net
Tue Dec 21 06:18:06 CST 2004
Francesc Altet wrote:
>Hi,
>
>I'm a bit lost with the next example:
>
>In [28]: from numarray import *
>In [29]: a=arange(10)
>In [30]: a.iscontiguous()
>Out[30]: 1
>In [31]: b=a[::2]
>In [32]: b.iscontiguous()
>Out[32]: 0
>
>That seems to suggest that b shares the same data buffer than a. Indeed:
>
>In [36]: a._data
>Out[36]: <memory at 0x082494d8 with size:0x00000028 held by object 0xb762c260 aliasing object 0x00000000>
>In [37]: b._data
>Out[37]: <memory at 0x082494d8 with size:0x00000028 held by object 0xb762c260 aliasing object 0x00000000>
>
>
OK so far.
>At this point, I believe that _bytestride should be different on both
>arrays, but:
>
>In [33]: a._bytestride
>Out[33]: 4
>In [34]: b._bytestride
>Out[34]: 4
>
>while I expected to find b._bytestride equal to 8.
>
>Is that an error or a lack of understanding on my part?
>
>
What you are looking for is _strides. Since, in general, arrays can be
multidimensional, the stride(s) need to be specified as a sequence.
_bytestride appears to be equivalent to itemsize(); that is, it tells
how many bytes are required to represent one item of the array. Here's
what strides looks like in your case:
>>> a._strides
(4,)
>>> b._strides
(8,)
Hope that helps,
-tim
>Cheers,
>
>
>
More information about the Numpy-discussion
mailing list