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

Alexander Belopolsky ndarray at mac.com
Wed Oct 29 13:07:42 EDT 2014


On Tue, Oct 28, 2014 at 10:11 PM, Nathaniel Smith <njs at pobox.com> wrote:

> > I don't think so - I think all the heavy lifting is already done in
> flatiter.  The missing parts are mostly trivial things like .size or .shape
> or can be fudged by coercing to true ndarray using existing
> flatiter.__array__ method.
>
> Now try .resize()...
>

Simple:

def resize(self, shape):
    if self.shape == shape:
        return
    else:
        raise ValueError


>From ndarray.resize documentation:

Raises
------
ValueError
    If `a` does not own its own data or references or views to it exist,
    and the data memory must be changed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141029/2ced961e/attachment.html>


More information about the NumPy-Discussion mailing list