numpy.zeros(shape, dtype=None, order='C')
Return array filled with zeors of given shape and type.
shape | Int, or sequence ( 2,3), shape of the output array |
dtype | data-type( Optional ), Data Type of returned array. |
order | {'C','F'} Optional, how the output is to be stored. C- style or Fortan style |
![]() | ![]() |
| Shape: (3, 4) Dimension 2 | Shape: (4, 3) Dimension 2 |
import numpy as np
ar=np.zeros(4)
print(ar) # [0. 0. 0. 0.]
Let us use different value for shape
ar=np.zeros((4,2))
print(ar)
Output
[[0. 0.]
[0. 0.]
[0. 0.]
[0. 0.]]
ar=np.zeros((4,1))
Output
[[0.]
[0.]
[0.]
[0.]]
import numpy as np
ar=np.zeros(4,dtype=str)
print(ar) # ['' '' '' '']
Output
['' '' '' '']
dtype=float
ar=np.zeros(4,dtype=float)
Output
[0. 0. 0. 0.]
dtype=int
my=np.zeros(4,dtype=int)
Output
[0 0 0 0]
Numpy
eye()
bincount()
arange()
linspace()
Advanced Array creation
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.