28 Mar Initialize Numpy arrays
To Initialize NumPy arrays, use the numpy.zeros() method. Using this method, initialize numpy arrays with zeros. Let us see some examples.
Initialize numpy arrays with zeros
Let us see an example to initialize numpy arrays with zeros. We are creating a 2×3 array with zeros:
1 2 3 4 5 6 7 |
import numpy as np n = np.zeros([2, 3]) print(n) print(type(n)) |
Output
1 2 3 4 5 |
[[0. 0. 0.] [0. 0. 0.]] <class 'numpy.ndarray'> |
Let us see another example. We are creating a 4×4 array with zeros:
1 2 3 4 5 6 7 |
import numpy as np n = np.zeros((4, 4)) print(n) print(type(n)) |
Output
1 2 3 4 5 6 7 |
[[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]] <class 'numpy.ndarray'> |
Video Tutorial
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
No Comments