ben.root at ou.edu
Tue Jul 23 10:57:58 EDT 2013
On Tue, Jul 23, 2013 at 10:46 AM, Pauli Virtanen <pav at iki.fi> wrote:
> 23.07.2013 17:34, Benjamin Root kirjoitti:
> > Don't assume .flat is not commonly used. A common idiom in matlab is
> > "a[:]" to flatten an array. When porting code over from matlab, it is
> > typical to replace that with either "a.flat" or "a.flatten()", depending
> > on whether an iterator or an array is needed.
> It is much more rarely used than `ravel()` and `flatten()`, as can be
> verified by grepping e.g. the matplotlib source code.
The matplotlib source code is not a port from Matlab, so grepping that
wouldn't prove anything.
Meanwhile, the "NumPy for Matlab users" page notes that a.flatten() makes a
copy. A newbie to NumPy would then (correctly) look up the documentation
for a.flatten() and see in the "See Also" section that "a.flat" is just an
iterator rather than a copy, and would often use that to avoid the copy.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion