First page Back Continue Last page Overview Graphics

Zeros and Ones

The methods zeros() and ones() provide a comfortable possibility to fill an array with given shape and type filled with zeros or ones:

>>> np.ones((2,3))

array([[ 1., 1., 1.],

[ 1., 1., 1.]])

>>> np.ones((3,4),dtype=int)

array([[1, 1, 1, 1],

[1, 1, 1, 1],

[1, 1, 1, 1]])

>>> np.zeros((3,4),dtype=int)

array([[0, 0, 0, 0],

[0, 0, 0, 0],

[0, 0, 0, 0]])

>>>