Create empty NumPy Array | Example code

There are two ways to create an empty NumPy Array. NumPy.zeros and NumPy.empty Both of these methods differ slightly.

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

numpy.empty(shape, dtype=float, order='C')
  • Shape – Shape of the new array, e.g., (2, 3) or 2.
  • dtype (optional) – The desired data-type for the array,e.g., numpy.int8. Default is numpy.float64.
  • order (optional) – Indicates whether multi-dimensional data should be stored in row-major (C-style) or column-major (Fortran-style) order in memory.

Example Create an empty NumPy Array

Simple example code. You have to import the NumPy module for both examples.


NumPy empty creates a Numpy matrix/array without initializing it with any values. It contains a junk value.

import numpy as np

emptyArr = np.empty((3, 2))


Create empty NumPy Array


NumPy zero creates a NumPy matrix/array and initializes all of its values to 0.

import numpy as np

zeroArr = np.zeros((2, 3))


zero NumPy Array

Do comment if you have any questions on this Python NumPy topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.