👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.

In Python, how to create an empty NumPy array?

There are several ways to create an empty NumPy array in Python. In the following we'll assume NumPy is imported according to the following:

import numpy as np

Create an empty Numpy array:

>>> a = np.array([])
array([], dtype=float64)

Create a NumPy array filled with zero of a given size:

>>> a = np.zeros([4,3])
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]])

Create an uninitialized NumPy array with a given size:

>>> a = np.empty([2,2])
array([[5.e-324, 5.e-324],
       [5.e-324, 0.e+000]])