Numpy zeros()

Numpy

numpy.zeros(shape, dtype=None, order='C')
Return array filled with zeors of given shape and type.
shapeInt, or sequence ( 2,3), shape of the output array
dtypedata-type( Optional ), Data Type of returned array.
order{'C','F'} Optional, how the output is to be stored. C- style or Fortan style
Zero array of shape(3,4)Zero array of shape(4,3)
Shape: (3, 4)
Dimension 2
Shape: (4, 3)
Dimension 2

Using shape

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.]]

dtype

We will try to return string dtype
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()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer