Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

NumPy zeros(): Create Arrays of Zeros with np.zeros

Create zero-filled NumPy arrays with np.zeros by choosing a shape and, when needed, a dtype or memory order. Compare zeros with zeros_like, empty, and full.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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:

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

  • like was added in NumPy 1.20. It lets an array-like object implementing __array_function__ determine a compatible result.
  • device was 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.

Best Value
NumPy - Python Library for Software Developers, Programmers T-Shirt
  • 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.