BetterDocs
Home
Docs

Creation | np.empty()

Method:

np.empty(shape, dtype=np.float64, order='C', *, device=None, like=None)

Creates a NumPy array of the entered shape without initializing entries.

Returns:

np.ndarray

Parameters:

shape: (list, tuple)-

Specifies the dimensions of the array to return.

import numpy as np
# (row, col) or [row, col] to be fed as shape
empty_array = np.empty(shape=(2, 3))
print(empty_array)
'''
Output: (Garbage value)
[[1. 1. 1.]
 [1. 1. 1.]]
 '''

dtype: np.float64, Optional-

The desired data-type for the array.

import numpy as np
empty_array = np.empty((2, 3), dtype=np.int16)
print(empty_array)
'''
Output: (Garbage value)
[[-1783 25878 21981]
 [    0     0     0]]
 '''

Values: +

By passing the dtype, you are implicitly converting the values to the passed dtype.

order: {'C', 'F'}, Optional-

Specifies the memory layout order for multi-dimensional arrays.

order = C (default) +

order = F +

Refer to np.array()  for better explanation & examples for order.

.ravel()  is a NumPy function used to flatten a multi-dimensional array into a 1D array.

device: None, Optional-

In NumPy 2.1, the device parameter in np.empty() is still in an early stage and currently only accepts "cpu" as a valid option. At this time, it is primarily there for future development, allowing the function to eventually support GPUs or other devices, but for now, it doesn't support GPU IDs directly.

like: None, Optional-

The like parameter in np.empty() was introduced to make array creation more flexible, particularly for compatibility with libraries that extend NumPy, like Dask, CuPy, or other libraries that create arrays compatible with np.ndarray but optimized for different backends (e.g., parallel processing or GPU-based arrays).


Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy