NumPy zeros()

The zeros() method creates a new array of given shape and type, filled with zeros.


zeros() Syntax

The syntax of zeros() is:

numpy.zeros(shape, dtype = None, order = 'C')

zeros() Arguments

The zeros() method takes three arguments:

  • shape - desired shape of the new array (can be int or tuple of int)
  • dtype (optional) - datatype of the new array
  • order (optional) - specifies the order in which the zeros are filled

zeros() Return Value

The zeros() method returns the array of given shape, order, and datatype filled with 0s.


Example 1: Create Array With zeros

Output

Float Array:  [0. 0. 0. 0. 0.]
Int Array:  [0 0 0 0 0]

If unspecified, the default dtype is float.


Example 2: Create nd-Array With zeros

Output

n-d array:
 [[0. 0. 0.]
 [0. 0. 0.]]