[Numpy-discussion] Why ndarray provides four ways to flatten?

Sebastian Berg sebastian at sipsolutions.net
Wed Oct 29 05:16:51 EDT 2014


On Di, 2014-10-28 at 14:03 -0400, Alan G Isaac wrote:
> On 10/28/2014 1:42 PM, Stephan Hoyer wrote:
> > np.nditer is a reasonable alternative to .flat (and it's documented as such), but it's a rather inelegant, kitchen-sink type function.
> 
> 
> I'm not sure what "reasonable" means here,
> other than "in principle, possible to use".
> 
> In particular, `flat` is much more elegant,
> and includes an automatic guarantee that the
> iterations will be in C-contiguous style.
> 

I don't really like flat (it is a pretty old part of numpy), but I
agree, while you can force nditer to be C-contiguous, nditer has its own
problems and is also pretty complex. I would argue that nditer it is a
"you know what you are doing" type of function... Or of course if you
want to understand the C-Api.
Unless you keep in mind how buffers are copied around inside it, using
half its features is dangerous.

- Sebastian

> Alan
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141029/be1b6df8/attachment.sig>


More information about the NumPy-Discussion mailing list