[Numpy-discussion] return value of array methods
Alan G Isaac
aisaac at american.edu
Sun Aug 31 13:19:58 EDT 2008
dmitrey wrote:
> As for me I can't understand the general rule: when numpy funcs return
> copy and when reference?
>
> For example why x.fill() returns None (do inplace modification) while
> x.ravel(), x.flatten() returns copy? Why the latters don't do inplace
> modification, as should be expected?
I take the rule to be to return the result when it is
a copy or a change of view. So,
these seem quite right, taken one at a time.
E.g., ``a.fill()`` changes `a` in place, and so returns None.
It does not make sense to think of ``ravel`` as doing
an in-place modification, it is just a change of view (if possible).
And ``flatten`` is specifically for insisting on a copy
rather than a change of view. Or so I understand things.
Alan Isaac
More information about the NumPy-Discussion
mailing list