Constant-valued numerical buffers
Initialize a matrix or tensor with a known constant before applying numerical operations.
NumPy · Function
Returns a new NumPy array with a specified shape, filled with a chosen value. Optional dtype, memory order, device, and like arguments control how the array is created.
numpy.full allocates and returns a new ndarray with the requested shape, filling every element from fill_value. dtype controls the resulting data type when specified, while order selects C- or Fortran-contiguous memory layout for multidimensional arrays; device and like support are optional parameters in the current stable signature.
numpy.full(*shape*, *fill_value*, *dtype=None*, *order='C'*, ***, *device=None*, *like=None*)| Name | Type | Description |
|---|---|---|
shape | int or sequence of ints | Shape of the new array; an integer or sequence of integers. |
fill_value | scalar or array_like | Value used to fill the array; it may be scalar or array-like. |
dtype | dtype, optional | Desired data type; None infers it from fill_value. |
order | {'C', 'F'}, optional | Memory layout for multidimensional data. |
device | str, optional | Device on which to create the array. |
like | array_like, optional | Reference object enabling array creation through its __array_function__ protocol. |
out: ndarray — An array of fill_value with the given shape, dtype, and order.
import numpy as np
values = np.full((2, 3), 7, dtype=np.int32)
print(values)
# [[7 7 7]
# [7 7 7]]Creates a 2-by-3 integer array whose every element is 7.
Initialize a matrix or tensor with a known constant before applying numerical operations.
Create an integer, floating-point, or other explicitly typed array for predictable computation.
Prepare arrays with row-major or column-major storage to match downstream access patterns.
numpy.full creates a new ndarray with the supplied shape and fills it with fill_value. The result has the requested dtype and memory order.
Follow-up: How can the fill value affect dtype when dtype is omitted? The dtype is inferred from the fill value, so explicitly pass dtype when a particular type is required.
shape may be an integer for a one-dimensional result or a sequence of integers for multiple dimensions. For example, 2 produces a length-two array, while (2, 3) produces two rows of three elements.
Follow-up: What happens when fill_value is array-like? Its values can populate the result according to the documented array-like fill behavior; test the intended shape when using non-scalars.
dtype is optional and specifies the desired data type of the new array. order is optional and chooses C- or Fortran-contiguous storage for multidimensional data.
Follow-up: When would order matter? It can matter for interoperability and performance in code that benefits from a particular traversal or memory layout.
numpy.full_likenumpy.emptynumpy.onesnumpy.zeros