full#

ivy.full(shape, fill_value, /, *, dtype=None, device=None, out=None)[source]#

Return a new array having a specified shape and filled with fill_value.

Parameters:
  • shape (Union[Shape, NativeShape]) – output array shape.

  • fill_value (Union[float, bool]) – fill value.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type must be inferred from fill_value. If the fill value is an int, the output array data type must be the default integer data type. If the fill value is a float, the output array data type must be the default floating-point data type. If the fill value is a bool, the output array must have boolean data type. Default: None.

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to place the created array. Default: None.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array where every element is equal to fill_value.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Shape input:

>>> shape = ivy.Shape((2,2))
>>> fill_value = 8.6
>>> x = ivy.full(shape, fill_value)
>>> print(x)
ivy.array([[8.6, 8.6],
           [8.6, 8.6]])

With ivy.NativeShape input:

>>> shape = ivy.NativeShape((2, 2, 2))
>>> fill_value = True
>>> dtype = ivy.bool
>>> device = ivy.Device('cpu')
>>> x = ivy.full(shape, fill_value, dtype=dtype, device=device)
>>> print(x)
ivy.array([[[True,  True],
            [True,  True]],
           [[True,  True],
            [True,  True]]])

With ivy.NativeDevice input:

>>> shape = ivy.NativeShape((1, 2))
>>> fill_value = 0.68
>>> dtype = ivy.float64
>>> device = ivy.NativeDevice('cpu')
>>> x = ivy.full(shape, fill_value, dtype=dtype, device=device)
>>> print(x)
ivy.array([[0.68, 0.68]])

With ivy.Container input:

>>> shape = ivy.Container(a=ivy.NativeShape((2, 1)), b=ivy.Shape((2, 1, 2)))
>>> fill_value = ivy.Container(a=0.99, b=False)
>>> dtype = ivy.Container(a=ivy.float64, b=ivy.bool)
>>> device = ivy.Container(a=ivy.NativeDevice('cpu'), b=ivy.Device('cpu'))
>>> x = ivy.full(shape, fill_value, dtype=dtype, device=device)
>>> print(x)
{
    a: ivy.array([[0.99],
                  [0.99]]),
    b: ivy.array([[[False, False]],
                  [[False, False]]])
}