NumPy Tutorial NumPy Statistics NumPy References

NumPy - empty() function



The NumPy empty() function returns a new array of specified shape and data type, with uninitialized entries.

Syntax

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

Parameters

shape Required. Specify shape of the returned array in form of int or tuple of ints.
dtype Optional. Specify the desired data-type for the array. Default: float
order Optional. Specify whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory. Two possible values are: C (C-style) and F (Fortran-style). Default: 'C'

Return Value

Returns an array (ndarray) of uninitialized (arbitrary) data with the given shape, dtype, and order.

Example: Create 2-D array of uninitialized data

In the example below, empty() function is used to create a 2 dimensional array of uninitialized (arbitrary) data of specified shape.

import numpy as np
Arr = np.empty((2,2))
print(Arr)

The output of the above code will be:

[[  6.93360212e-310   6.93360212e-310]
 [  6.93359915e-310   6.93359743e-310]]

Example: empty() function with dtype parameter

The empty() function can be used with dtype parameter to provide the data type of the elements of the array. In the example below, data type of the returned array is complex.

import numpy as np
Arr = np.empty((2,1), dtype=complex)
print(Arr)

The output of the above code will be:

[[  6.91055518e-310 +6.91055518e-310j]
 [  6.91055221e-310 +6.91055049e-310j]]

❮ NumPy - Functions