BetterDocs
Home
Docs

Creation | np.full()

Method:

np.full(shape, fill_value, dtype=None, order='C', *, device=None, like=None)

Creates an array filled with the specified fill_value.

Returns:

np.ndarray

Parameters:

shape: dimension-

Dimensions of the new array.

import numpy as np

# 2x2 array filled with 0
full_array = np.full(shape=(2, 2), fill_value=0)
print(full_array)
'''
Output:
[[0 0]
 [0 0]]
'''

The shape of an np.ndarray is related to it's dimensions.

shape is an array of numbers representing the length of each dimension.

fill_value: (int, str, bool, array-like)-

Value to fill the array with.

fill_value = int +

fill_value = str +

fill_value = bool +

fill_value = array-like +

When passing array-like to fill_value, if the fill_value is multi-dimensional, the values passed must be less than or equal to shape parameter.

When passing array-like to fill_value, the values in fill_value must be of the same dtype, if not, all the values will be converted to str.

dtype: None, Optional-

The desired data-type for the NumPy array is inferred from the fill_value.

import numpy as np

# 2x2 array filled with 4
full_array = np.full((2, 2), 4, dtype=np.float64)
print(full_array)
'''
[[4. 4.]
 [4. 4.]]
'''

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 +

.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.full() 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.full() 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