[Numpy-discussion] ndarray.fill and ma.array.filled

Sasha ndarray at mac.com
Wed Mar 22 17:40:06 CST 2006

On 3/22/06, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> Tim makes a good point here.  Should the reshape method be fixed to
> always return a copy?  The semantics a.shape = (...) could still be used
> to re-shape contiguous arrays where possible.

Reshape never copies the data:
>>> x = ones(4)
>>> x.reshape((2,2)).__array_data__ == x.__array_data__

The only inconsistency is that

>>> x.reshape((2,2)) is x
>>> x.reshape((4,)) is x

I agree that this is unnecessary, but don't see much of a problem.

+0 here

> However, whether or not reshape returns a copy is consistent (but
> perhaps not explicitly explained).

To me consistency means "is independent of the input."  Whether or not
reshape creates a new python object depends on the value of the
argument.  I would call it inconsistency.

> We will still have .ravel() which sometimes copies and sometimes doesn't.

Ravel should be a shortcut for x.reshape((x.size,)), so it is really
the same question.

+0 (to make ravel always return a new python object)

More information about the Numpy-discussion mailing list