Use np.zeros(shape, dtype=...) to create a new NumPy array whose elements are all zero. Pass a single integer for a one-dimensional array or a tuple for multiple dimensions; unless you specify otherwise, the result uses float64 values and C-order memory layout.
How to create an array with np.zeros
Import NumPy, then give np.zeros the shape you want. For example:
As an Amazon Associate I earn from qualifying purchases.
import numpy as np
one_dimensional = np.zeros(5)
matrix = np.zeros((2, 3), dtype=int)
The first call creates a one-dimensional array with five zeros. The second creates a two-row, three-column array of integers. NumPy documents the function as returning a new array of the given shape and type, filled with zeros: numpy.zeros API reference.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Choose the shape and data type
Shape sets the dimensions
Pass one integer for a one-dimensional array, such as np.zeros(5). For two or more dimensions, pass a tuple: np.zeros((2, 3)) creates two rows and three columns. The shape describes the array’s dimensions, not the values it contains.
#1 Best Overall
Dtype determines what kind of zeros you get
The default dtype is numpy.float64, so np.zeros(5) produces floating-point zeros. Choose a dtype explicitly when you need integers or another type:
ints = np.zeros((2, 3), dtype=int)
small_ints = np.zeros(5, dtype=np.int8)
The official examples also show a structured dtype, which creates zero-valued fields within each array element:
Rank #2
records = np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')])
See the NumPy array creation guide for the broader context of creating arrays and choosing their types.
When memory order matters
The order argument controls how multidimensional data is laid out in memory; it does not change the array’s shape or zero values. The default, order='C', uses C-style row-major order. Set order='F' for Fortran-style column-major order when that layout suits the surrounding computation:
Rank #3
row_major = np.zeros((2, 3))
column_major = np.zeros((2, 3), order='F')
Choose between zeros, zeros_like, empty, and full
| Need | Function | What it does |
|---|---|---|
| You know the shape and want to choose the dtype directly | np.zeros(shape, dtype=...) |
Creates a zero-filled array of the specified shape and type. |
| You want zeros matching an existing array | np.zeros_like(a) |
Uses the input array’s shape and dtype by default, with supported overrides. See the array-creation routines index. |
| You will assign every element before reading it | np.empty(shape, dtype=...) |
Allocates an array without initializing ordinary numeric entries. Their values are arbitrary until assigned; reading them first is unsafe. See the numpy.empty API reference. |
| You need every element set to a constant other than zero | np.full(shape, fill_value) |
Creates an array filled with the value you specify. See the array-creation routines index. |
Optional interoperability parameters
The current signature is numpy.zeros(shape, dtype=None, order='C', *, device=None, like=None). Most code only needs shape and, when appropriate, dtype.
likewas added in NumPy 1.20. It lets an array-like object implementing__array_function__determine a compatible result.devicewas added in NumPy 2.0 for Array API interoperability. When supplied, the documented supported value is"cpu".
For details and version notes, consult the current NumPy zeros reference.
Quick Recap
Best Value
- NumPy is perfect for data scientists and engineers using Python. NumPy powers machine learning, financial modeling, and AI development. NumPy is essential for data analysis, physics research, big data processing in tech, and science research analytics
- NumPy offers mathematical functions, random number generators, linear algebra routines, Fourier transforms. NumPy Python library adds support for large multi-dimensional arrays and matrices, with high-level mathematical functions to operate on these arrays
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →




