How to create numpy array with zeros?

Numpy offers various functions for creating arrays. Let’s see how to create numpy array populated just with zeros in Numpy Python library.
numpy zeros array

Using the zeros Function

To create Numpy array populated with just zeros you should use zeros function.

import numpy as np

zeros_array = np.zeros(shape=(6, 5))
print(zeros_array)

This code snippet creates a 6 x 5 NumPy array populated with just zeros. The print() statement prints the array to the console.

See also  How to convert list to Numpy array

In zeros syntax only shape argument does not the default value. I set the shape in a tuple and got 6 x 5 shaped array. You can experiment with different shapes by modifying the values inside the tuple in the shape argument.

Customizing Data Type

You can specify the data type of the array elements using the dtype argument:

float_zeros = np.zeros((3, 3), dtype=np.float32)
print(float_zeros)

This creates a 3 x 3 array of zeros with a float data type.

See also  How to find index of max value in Numpy?