[Numpy-discussion] isn't it a bug in array.fill()?
dmitrey
dmitrey.kroshko at scipy.org
Fri Aug 29 14:02:29 EDT 2008
Keith Goodman wrote:
> On Fri, Aug 29, 2008 at 10:51 AM, Keith Goodman <kwgoodman at gmail.com> wrote:
>
>> On Fri, Aug 29, 2008 at 10:42 AM, dmitrey <dmitrey.kroshko at scipy.org> wrote:
>>
>>> Keith Goodman wrote:
>>>
>>>> Yeah, I do stuff like that too. fill works in place so it returns None.
>>>>
>>>>
>>>>
>>>>>> x = np.array([1,2])
>>>>>> x.fill(10)
>>>>>> x
>>>>>>
>>>>>>
>>>> array([10, 10])
>>>>
>>>>
>>>>>> x = x.fill(10) # <-- Danger!
>>>>>> print x
>>>>>>
>>>>>>
>>>> None
>>>>
>>>>
>>> Since result "None" is never used it would be better to return reference
>>> to the modified array, ...
>>>
>> I like that idea. A lot of numpy functions return a reference to the
>> modified array when the output array (out) is specified.
>>
>
> But python doesn't do that. For example, x.sort() returns None in
> python. Should it return None in numpy?
>
I think the value "None" that any method always returns is hardly used
by anyone, so backward compatibility will not suffer much. Since
in-place modification remains (along with new-style returning value that
is reference to the array), there should be no backward
incompatibilities at all.
D.
More information about the NumPy-Discussion
mailing list