Thursday, September 25, 2025
HomeLanguagesCreate a Numpy array filled with all zeros | Python

Create a Numpy array filled with all zeros | Python

In this article, we will learn how to create a Numpy array filled with all zeros, given the shape and type of array.

We can use Numpy.zeros() method to do this task. This method takes three parameters, 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 array with all zeros
import numpy as geek 
  
a = geek.zeros(3, dtype = int
print("Matrix a : \n", a) 
  
b = geek.zeros([3, 3], dtype = int
print("\nMatrix b : \n", b) 


Output:

Matrix a : 
 [0 0 0]

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

Example #2:




# Python Program to create array with all zeros
import numpy as geek 
  
c = geek.zeros([5, 3]) 
print("\nMatrix c : \n", c) 
  
d = geek.zeros([5, 2], dtype = float
print("\nMatrix d : \n", d) 


Output:

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

RELATED ARTICLES

Most Popular

Dominic
32319 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6680 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6794 POSTS0 COMMENTS
Ted Musemwa
7070 POSTS0 COMMENTS
Thapelo Manthata
6753 POSTS0 COMMENTS
Umr Jansen
6761 POSTS0 COMMENTS