Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.full

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.

How it works

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.

Syntax

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

Parameters

NameTypeDescription
shapeint or sequence of intsShape of the new array; an integer or sequence of integers.
fill_valuescalar or array_likeValue used to fill the array; it may be scalar or array-like.
dtypedtype, optionalDesired data type; None infers it from fill_value.
order{'C', 'F'}, optionalMemory layout for multidimensional data.
devicestr, optionalDevice on which to create the array.
likearray_like, optionalReference object enabling array creation through its __array_function__ protocol.

Returns

out: ndarray — An array of fill_value with the given shape, dtype, and order.

Key points

  • The function returns a newly allocated array whose dimensions and element type are controlled by shape and dtype, with values initialized from fill_value.
  • Pass one integer for a one-dimensional shape or a sequence such as (2, 3) for a matrix.
  • Use dtype to request the output element type instead of relying on inference.
  • If dtype is None, NumPy derives the type from fill_value.
  • The returned ndarray reflects all three requested properties: contents, shape, and layout.

Common mistakes

  • The order argument affects multidimensional memory layout: use 'C' for row-major layout or 'F' for column-major layout.

Example: Create a filled array

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.

When to use it

Constant-valued numerical buffers

Initialize a matrix or tensor with a known constant before applying numerical operations.

Controlled dtype initialization

Create an integer, floating-point, or other explicitly typed array for predictable computation.

Memory-layout preparation

Prepare arrays with row-major or column-major storage to match downstream access patterns.

Interview questions

QWhat does numpy.full return?

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.

QWhat forms can shape take?

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.

QWhat are dtype and order used for?

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_like
  • numpy.empty
  • numpy.ones
  • numpy.zeros

Source: numpy.full — NumPy v2.5 Manual. Checked 2026-10-15.