For a numerical array—especially one that needs multiple dimensions—use NumPy: np.zeros(5) creates five zeros in a NumPy ndarray. Python’s word “array” can also mean a built-in list or a typed array.array, so the right method depends on the type your code needs.
1. Create a NumPy array of zeros
Use numpy.zeros when your code expects a NumPy ndarray or needs NumPy’s numerical operations and multidimensional shapes. The function returns a new array filled with zeros. Its default element type is numpy.float64; specify dtype if you want integers or another type.
As an Amazon Associate I earn from qualifying purchases.
import numpy as np
zeros = np.zeros(5) # one-dimensional; float64 by default
integer_zeros = np.zeros(5, dtype=int) # integer dtype
matrix = np.zeros((2, 3), dtype=int) # two rows, three columns
A single number such as 5 defines a one-dimensional shape. Use a tuple such as (2, 3) for two dimensions. The optional order parameter controls C-style row-major or Fortran-style column-major memory layout. The device keyword was added in NumPy 2.0.0; if supplied for Array API interoperability, it must be "cpu". The like keyword, added in NumPy 1.20.0, can let a compatible array-like object handle array creation.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11See the NumPy zeros reference for the full signature and parameter details.
#1 Best Overall
2. Make a simple Python list with repetition
For a flat sequence of zero values in ordinary Python code, repeat the integer zero:
n = 5
zeros = [0] * n
This returns a built-in list, not a NumPy ndarray. Repetition is appropriate here because 0 is immutable. Repeating a mutable object, such as a nested list, would repeat references to the same object.
Rank #2
3. Make a list with a comprehension
A list comprehension also returns a built-in list. It is useful when the value expression may need to become more involved:
Free tools Windows power users keep installed
One-click scans. No signup required.
n = 5
zeros = [0 for _ in range(n)]
For a two-dimensional nested list, construct a separate row on each iteration:
rows, cols = 2, 3
matrix = [[0 for _ in range(cols)] for _ in range(rows)]
# This is also safe for immutable zeros:
matrix = [[0] * cols for _ in range(rows)]
Avoid [[0] * cols] * rows if you plan to change individual rows. The outer repetition makes multiple references to the same inner list, so changing one row changes them all. Python’s built-in types documentation explains sequence repetition and list construction.
4. Use the standard-library array.array
For a mutable sequence of constrained basic numeric values without NumPy, use the standard-library array module:
from array import array
zeros = array('i', [0]) * 5
This returns an array.array, not a list or ndarray. The type code 'i' requests the C int type. The element representation and size depend on the machine architecture and C implementation, so this is not the same type system as NumPy’s dtypes. See Python’s array module documentation.
Recommended Free Tools
Which method should you choose?
| Method | Returned type | Best fit |
|---|---|---|
np.zeros(shape, dtype=...) |
NumPy ndarray | NumPy operations, multidimensional numerical data, or code expecting an ndarray |
[0] * n or a list comprehension |
Built-in Python list | Simple Python sequence work |
array('i', [0]) * n |
Standard-library array.array |
A sequence of constrained basic numeric values using a type code |
Choose by the type expected by the code that will consume the values, then set the shape and element type. If integer elements matter in NumPy, pass dtype=int rather than relying on the default.
Best Value
Why not use np.empty?
np.empty creates an array with uninitialized contents; it does not fill the elements with zeros. Use it only when every element will be assigned before being read. For a zero-initialization requirement, use np.zeros. NumPy’s user guide describes the uninitialized result.
Quick Recap
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.




