[Numpy-discussion] problem with view() and strided arrays?

Charles R Harris charlesr.harris@gmail....
Thu Apr 24 22:53:42 CDT 2008

On Thu, Apr 24, 2008 at 10:00 AM, Zachary Pincus <zachary.pincus@yale.edu>

> > It seems like 'view' won't create a view where the stride length is
> > not a whole multiple of the dtype's itemsize. However, since strides
> > are measured in bytes (right?), this shouldn't be a problem.
> Actually -- it seems like view() doesn't work with strided arrays at
> all. (?)
> In : a = numpy.ones((4,32), dtype=numpy.uint8)
> In : a.view(numpy.uint16).shape
> Out: (4, 16)
> In : a[:,:16].view(numpy.uint16)
> ValueError: new type not compatible with array.
> I think this might be a recent regression, because before I updated my
> numpy installation to the latest SVN version (to check if the bug was
> fixed!), I'm pretty sure this kind of operation worked.

Views only work for items of the same size. You are trying to view bytes as
two byte values. View is like strict pointer aliasing in C.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080424/afd595f6/attachment.html 

More information about the Numpy-discussion mailing list