Create Numpy Array Filled With All Zeros | python



We can use the Numpy.zeros () method to accomplish this task. This method takes three parameters, which are discussed below —

  shape:  integer or sequence of integers  order:  C_contiguous or F_contiguous C-contiguous order in memory (last index varies the fastest) C order means that operating row-rise on the array will be slightly quicker FORTRAN-contiguous order in memory (first index varies the fastest). F order means that column-wise operations will be faster.  dtype:  [optional, float (byDeafult)] Data type of returned array. 

Example # 1:

# Python program to create an array with all zeros

import numpy as geek 

 

a = geek.zeros ( 3 , dtype = int

print ( "Matrix a:" , a) 

 

b = geek.zeros ([ 3 , 3 ], dtype = int

print ( "Matrix b : " , b) 

Exit:

 Matrix a: [0 0 0] Matrix b: [[0 0 0] [0 0 0] [0 0 0]]  

Example # 2:

# Python program to create an array with all zeros

import numpy as geek 

 

c = geek.zeros ([ 5 , 3 ]) 

print ( "Matrix c:" , c) 

 

d = geek.zeros ([ 5 , 2 ], dtype = float

print ( "Matrix d:" , d) 

Exit:

 Matrix c: [[0. 0. 0.] [0. 0. 0.] [0. 0. 0.] [0. 0. 0.] [0. 0. 0.]] Matrix d: [[0. 0.] [0. 0.] [0. 0 .] [0. 0.] [0. 0.]]