NumPy zeros

  • Post category:NumPy

In this NumPy tutorial, you’ll learn how to use the NumPy zeros function in Python.

# import numpy module
import numpy as np

# create a numpy array
var = np.zeros((5,3))

# print the array
print(var)

Output:

[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]

NumPy zeros with integer data type

# import numpy module
import numpy as np

# create a numpy array
var = np.zeros((5,3), dtype= int)

# print the array
print(var)

Output:

[[0 0 0]
 [0 0 0]
 [0 0 0]
 [0 0 0]
 [0 0 0]]

Free resources to learn advanced skills: AiHints and CodeAllow