method
ndarray.fill(value)
Fill the array with a scalar value.
Parameters:valuescalarAll elements of a will be assigned this value.
Examples
>>> importnumpyasnp>>> a=np.array([1,2])>>> a.fill(0)>>> aarray([0, 0])>>> a=np.empty(2)>>> a.fill(1)>>> aarray([1., 1.])Fill expects a scalar value and always behaves the same as assigning to a single array element. The following is a rare example where this distinction is important:
>>> a=np.array([None,None],dtype=np.object_)>>> a[0]=np.array(3)>>> aarray([array(3), None], dtype=object)>>> a.fill(np.array(3))>>> aarray([array(3), array(3)], dtype=object)Where other forms of assignments will unpack the array being assigned:
>>> a[...]=np.array(3)>>> aarray([3, 3], dtype=object)