How to Create an Empty Matrix in NumPy

The syntax of creating an empty array is as follows.

Method 1: Full of zero


Method 2: Really empty

Note that, empty, unlike zeros, does not set the array values to zero, and may therefore be marginally faster. However, it requires the user to manually set all the values in the array, and thus you should double check before using it.


import numpy 
a = numpy.zeros(shape=(3,2))
[[0. 0.]
 [0. 0.]
 [0. 0.]]
b=numpy.empty(shape=(3, 2))
[[0. 0.]
 [0. 0.]
 [0. 0.]]

Note that, even using empty(), it still has zero in the matrix. However, there is no way to show a “really empty” matrix, really. Think about that! On the official Numpy website, they show something different and I copy here below. See that the values are not zero in the matrix, even with a very small value.

np.empty([2, 2])
array([[ -9.74499359e+001,   6.69583040e-309],
       [  2.13182611e-314,   3.06959433e-309]])         #uninitialized