[Numpy-discussion] Unexpected property of ndarray.fill

Sasha ndarray at mac.com
Mon Feb 27 10:17:16 CST 2006


The function ndarray.fill is documented as taking a scalar value, but
in the current implementation it accepts arrays as well and ignores
all but the first element

Example 1:
>>> x = empty(10)
>>> x.fill([1,2])
>>> x
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])

Example 2:
>>> y = empty((2,3))
>>> y.fill([1,2,3])
>>> y
array([[1, 1, 1],
       [1, 1, 1]])

I believe this somewhat unexpected. I would expect one of the
following to apply:

1. Exception in both examples
2. Exception in Example 1 and array([[1,2,3], [1,2,3]]) in Example 2
3. array([1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) in Example 1 and
array([[1,2,3], [1,2,3]]) in Example 2




More information about the Numpy-discussion mailing list