zeros() method in Numpy array by R4R Team

- zeros() is a python Numpy method which are create a new array or matrix with all elements are zero.
- It take shape,type as a argument and return a matrix.

Syntax-

numpy.zeros(shape,dtype=value)

Example-

numpy.zeros(2,dtype=int) will return
[0 0]

numpy.zeros((2,2),dtype=int) will return
[[0 0]
[0 0]]


program-

#import numpy
import numpy as np

#matrix of order 2x2 of int
print(np.zeros((2,2),dtype=int))

#matrix of order 2x2 of float
print(np.zeros((2,2),dtype=float))

#matrix of order 3x2 of int
print(np.zeros((3,2),dtype=int))

#matrix of order 3x3 of int
print(np.zeros((3,3),dtype=int))


output-

[[0 0]
[0 0]]

[[0. 0.]
[0. 0.]]

[[0 0]
[0 0]
[0 0]]

[[0 0 0]
[0 0 0]
[0 0 0]]




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!