Create a Numpy array filled with all zeros Python (original) (raw)

Last Updated : 28 Jan, 2025

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.

Let’s understand with the help of an example:

Python `

import numpy as np

Create a 1D array of zeros with 5 elements

array_1d = np.zeros(5) print(array_1d)

`

**Explanation:

Table of Content

Syntax of Creating a NumPy Array filled with all zeros

numpy.zeros(shape, dtype=float, order=’C’)

**Parameters

Creating a 2D Zero Array

Python `

import numpy as np

Create a 2D array of zeros (3 rows, 4 columns)

array_2d = np.zeros((3, 4)) print(array_2d)

`

Output

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

**Explnation:

Specifying Data Type

Python `

import numpy as np

Create an integer zero array

array_int = np.zeros((2, 3), dtype=int) print(array_int)

`

**Explanation:

Using Column-Major Order

Python `

import numpy as np

Create an array with column-major order

array_column_major = np.zeros((2, 3), order='F') print(array_column_major)

`

Output

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

**Explanation:

Similar Reads

Introduction







Creating NumPy Array













NumPy Array Manipulation


















Matrix in NumPy


















Operations on NumPy Array




Reshaping NumPy Array















Indexing NumPy Array






Arithmetic operations on NumPyArray










Linear Algebra in NumPy Array