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

Nathaniel Smith njs at pobox.com
Tue Oct 28 13:25:05 EDT 2014


On 28 Oct 2014 16:58, "Alexander Belopolsky" <ndarray at mac.com> wrote:
>
> On Mon, Oct 27, 2014 at 9:41 PM, Yuxiang Wang <yw5aj at virginia.edu> wrote:
>
>> In my opinion - because they don't do the same thing, especially when
>> you think in terms in lower-level.
>>
>> ndarray.flat returns an iterator; ndarray.flatten() returns a copy;
>> ndarray.ravel() only makes copies when necessary; ndarray.reshape() is
>> more general purpose, even though you can use it to flatten arrays.
>
>
> Out of the four ways, I find x.flat the most confusing.

I too would be curious to know why .flat exists (beyond "it seemed like a
good idea at the time" ;-)). I've always treated it as some weird legacy
thing and ignored it, and this has worked out well for me.

Is there any real problem where .flat is really the best solution? Should
we deprecate it, or at least warn people off from it officially?

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141028/dfd999c5/attachment.html>


More information about the NumPy-Discussion mailing list