[Numpy-discussion] .flat

Charles R Harris charlesr.harris at gmail.com
Tue Jul 23 13:05:06 EDT 2013


On Tue, Jul 23, 2013 at 10:36 AM, Pauli Virtanen <pav at iki.fi> wrote:

> 23.07.2013 19:22, Charles R Harris kirjoitti:
> [clip]
> > Grepping in my code, I find a lot of things like
> >
> > dfx = van.dot((ax2 - ax1).flat)
> >
> > IIRC, the flat version was faster than other methods.
>
> That goes through the same code path as
> `van.dot(np.asarray((ax2 - ax1).flat))`, which calls the `__array__`
> attribute of the flatiter object. If it's faster than .ravel(), that is
> surprising.
>
>
Well, I never use ravel, there are zero examples in my code ;) So you may
be correct.

I'm not sure the example I gave is the one where '*.flat' wins, but I
recall such a case and have just used flat a lot ever since.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130723/3a24fe55/attachment.html>


More information about the NumPy-Discussion mailing list