DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

Create an Empty Array in Python: Lists, NumPy Arrays, and np.empty()

Learn when to use [], np.array([]), np.empty(shape), and np.zeros()—and why these Python and NumPy options mean different things.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use [] to create an empty built-in Python list: items = []. For a zero-element NumPy array, use np.array([])—and specify dtype if the element type matters. NumPy’s np.empty(shape) is different: it allocates an array whose values are uninitialized, not a zero-element array.

What does “empty array” mean in Python?

Python has a built-in sequence type called a list, while NumPy provides the ndarray type for numerical array operations. The phrase “empty array” can refer to either an empty list or a NumPy array, so choose the syntax based on the type and behavior your code needs.

As an Amazon Associate I earn from qualifying purchases.

What you want Use What it creates
Flexible, empty Python sequence items = [] A mutable list with no elements
NumPy array with zero elements np.array([], dtype=float) An ndarray with no elements and an explicitly selected dtype
NumPy array of a chosen shape, with values to fill later np.empty(shape) Allocated array storage whose values are uninitialized
NumPy array of a chosen shape, initialized to zero np.zeros(shape, dtype=...) An array whose elements start at zero

Create an empty Python list with []

For general-purpose Python code, the simplest empty sequence is a list:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
items = []
items.append("first")

Lists are mutable and can grow as you append values. They can also hold values of different types. The Python tutorial’s data-structures documentation describes lists and their operations.

[] creates a list, not a NumPy ndarray. If later code specifically expects NumPy array behavior, create an ndarray instead.

Create a zero-element NumPy array

Import NumPy, then pass an empty sequence to np.array:

import numpy as np

empty_vector = np.array([], dtype=float)

This creates an ndarray with zero elements. The optional dtype argument selects the data type for array elements; specifying it is useful when later code depends on a particular type. NumPy documents the accepted inputs and optional data type in its numpy.array reference.

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

If the dtype is not important to your use case, the shorter form is np.array([]). Use an explicit dtype when you want the intended type to be clear and stable.

Why np.empty(shape) is not a zero-element array

The name can be misleading: np.empty(shape) creates an array with the requested shape, but it does not initialize ordinary numeric values to zero. Its elements contain arbitrary values until your code assigns them. For example:

buffer = np.empty(3, dtype=int)
buffer[:] = [10, 20, 30]

Assign every element before reading from the array. NumPy describes this behavior in the numpy.empty reference. Use it when you intend to fill allocated storage yourself—not when you need an array with zero elements or zero-valued elements.

Use np.zeros when values must start at zero

If you need a NumPy array of a particular shape and every element should begin at zero, use np.zeros:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
zeros = np.zeros(3, dtype=int)

This creates a three-element integer array initialized with zeros. The numpy.zeros reference documents the shape and dtype parameters.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a list or a NumPy array

  • Choose a list for a flexible, general-purpose sequence that you may grow or use for mixed types.
  • Choose a NumPy array when your data and operations suit numerical arrays, and you want an ndarray.
  • Choose np.array([]) when the NumPy array should contain zero elements.
  • Choose np.empty(shape) only when you need allocated storage and will assign values before reading them.
  • Choose np.zeros(shape) when the array needs elements initialized to zero.

NumPy’s beginner guide introduces arrays and how they differ from Python lists.

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.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
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.