How to create an empty array in NumPy

You can create an empty array in NumPy with the following code. If you want to learn Python then I will highly recommend you to read This Book.

How to create an empty array in NumPy
How to create an empty array in NumPy

Empty Array (Meaning 1)

import numpy as np
a = np.array([])
print(a)
print(type(a))
print(a.ndim)
Output:
[]
<class 'numpy.ndarray'>
1

Empty Array (Meaning 2)

import numpy as np
a = np.empty((3,3))
print(a)
Output:
[[ 0.00000000e+000  0.00000000e+000  0.00000000e+000]
 [ 0.00000000e+000  0.00000000e+000  6.85763116e-321]
 [ 7.25083853e+173 -1.06828331e-149  5.72918743e+250]]

Array with Zeros

import numpy as np
a = np.zeros((3,3))
print(a)
Output:
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]

People are also reading:

Best Python Books

What is Computer Vision? Examples, Applications, Techniques

Top 10 Computer Vision Books with Python

Books for Machine Learning (ML)

Free Learning Resources

Leave a Comment

Your email address will not be published.