How to Create an Empty Array in Python

To create an empty array in Python, you can use the numpy.zeros() function from the numpy library.

The following example shows how to create an empty array in Python using the numpy.zeros() function.

Using numpy.zeros() Function

We can use the numpy.zeros() function to create an empty array.

Suppose we want to create a 3x3 empty array:

import numpy as np

# Create empty array
empty_arr = np.zeros((3, 3))

# Show array
print(empty_arr)

Output: 👇️

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

In this example, we use the numpy.zeros() function to create a 3x3 empty array empty_arr. The output shows the empty array filled with zeros.

Conclusion

We can use the numpy.zeros() function from the numpy library to create an empty array in Python.