Create NumPy Array by zeros()
2 min readJul 22, 2024
The numpy.zeros() function can be used to create a new array of given shape and type, filled with zeros.
Syntax:
numpy.zeros(shape,dtype=float, order = ‘c’, *, like=None )
Returns an array only with zeros.
Default value of dtype is always float.
Here’s a breakdown of its parameters:
- shape: int or tuple of integer type. Shape of the new array, e.g., (2, 3)
- dtype: data-type, optional. Desired output data-type for the array, e.g., numpy.int8. Default is numpy.float64.
- order: {‘C’, ‘F’}, optional. Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.
- like: array_like, optional. Reference object to allow the creation of arrays which are not NumPy arrays.
Examples given below:
We can create any one or more than one dimensional arrays.
Example of 4-D array
4-D Arrays means a group of 3-D arrays:
np.zeros((2,3,4,5), dtype=int)
Explanation of above example:
- Every 4-D Array contains 3-D Arrays. Here, contains two 3-D Arrays.
- Every 3-D Array contains 2-D Arrays. So, every three dimensional array has three 2-D arrays
- Every 2-D Array contains 4 rows and 5 columns
- Total number of elements : 2*3*4*5 =120
That’s it for now, let’s deep dive into NumPy in my upcoming blogs.
And can learn more from my Github profile:
Also Matplotlib learnings from github:
Pandas Learnings from github:
Check some of my other blogs in this series: