[Numpy-discussion] bug? in len(arr.flat)

Sebastian Haase haase at msg.ucsf.edu
Fri Oct 29 09:03:25 EDT 2004


Of course !  sorry I forgot.

Thanks,
Sebastian


On Friday 29 October 2004 06:26 am, Todd Miller wrote:
> On Wed, 2004-10-27 at 12:58, Sebastian Haase wrote:
> > Hi,
> > I have a (UInt16) 3d data stack and want to get to it's underlying buffer
> > (to (later) feed it into memmap) ...
> > I noticed that len(pr2._flat) is half of len(pr2._data) - like it doesn't
> > multiply itemsize in.
> >
> > >>> pr2.shape
> >
> > (40, 512, 512)
> >
> > >>> pr2.flat.shape
> >
> > (10485760)
> >
> > >>> 512*512*40
> >
> > 10485760
> >
> > >>> len(pr2.flat)
> >
> > 10485760
> >
> > >>> pr2.flat._itemsize
> >
> > 2
> >
> > >>> len(pr2._data)
> >
> > 20971520
> >
> > >>> pr2._byteoffset
> >
> > 0
> >
> > Is this a bug
>
> No.
>
> > or am I missunderstanding ?
>
> Yes.  _data is "an object which supports the buffer protocol".  In this
> context,  it is effectively a string and thus the product of the total
> number of elements and the itemsize.  (We'll ignore for now the fact
> that not every array uses the entire buffer.)  In contrast, shape(.flat)
> is only the total number of elements and is independent of itemsize.
>
> Regards,
> Todd
>
>
>
>
> -------------------------------------------------------
> This Newsletter Sponsored by: Macrovision
> For reliable Linux application installations, use the industry's leading
> setup authoring tool, InstallShield X. Learn more and evaluate
> today. http://clk.atdmt.com/MSI/go/ins0030000001msi/direct/01/
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion




More information about the NumPy-Discussion mailing list