[Numpy-discussion] isn't it a bug in array.fill()?

dmitrey dmitrey.kroshko@scipy....
Fri Aug 29 12:42:01 CDT 2008


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, it would decrease number of bugs. The last 
expression can raise very seldom in untested cases, I have revealed one 
of this recently in my code:

if some_seldom_cond:
   r = empty(n, bool).fill(True)
else:
   r = None

So, as you see, r was always None

D.


More information about the Numpy-discussion mailing list