On Tue, Jul 23, 2013 at 10:46 AM, Pauli Virtanen <p...@iki.fi> wrote:
> 23.07.2013 17:34, Benjamin Root kirjoitti: > [clip] > > 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. Cheers! Ben Root
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion