full_like#

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

Return a new array filled with fill_value and having the same shape as an input array x .

Parameters:
  • x (Union[Array, NativeArray]) – input array from which to derive the output array shape.

  • fill_value (Number) – Scalar 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 x. Default: None.

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to place the created array. If device is None, the output array device must be inferred from x. 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 having the same shape as x and 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 int datatype:

>>> x = ivy.array([1, 2, 3, 4, 5, 6])
>>> fill_value = 1
>>> y = ivy.full_like(x, fill_value)
>>> print(y)
ivy.array([1, 1, 1, 1, 1, 1])
>>> fill_value = 0.000123
>>> x = ivy.ones(5)
>>> y = ivy.full_like(x, fill_value)
>>> print(y)
ivy.array([0.000123, 0.000123, 0.000123, 0.000123, 0.000123])

With float datatype:

>>> x = ivy.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
>>> fill_value = 0.000123
>>> y = ivy.full_like(x, fill_value)
>>> print(y)
ivy.array([0.000123, 0.000123, 0.000123, 0.000123, 0.000123, 0.000123])

With ivy.NativeArray input:

>>> x = ivy.native_array([3.0, 8.0])
>>> fill_value = 0.000123
>>> y = ivy.full_like(x,fill_value)
>>> print(y)
ivy.array([0.000123, 0.000123])
>>> x = ivy.native_array([[3., 8., 2.], [2., 8., 3.]])
>>> y = ivy.full_like(x, fill_value)
>>> print(y)
ivy.array([[0.000123, 0.000123, 0.000123],
           [0.000123, 0.000123, 0.000123]])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([1.2, 2.2324, 3.234]),
...                   b=ivy.array([4.123, 5.23, 6.23]))
>>> fill_value = 15.0
>>> y = ivy.full_like(x, fill_value)
>>> print(y)
{
    a: ivy.array([15., 15., 15.]),
    b: ivy.array([15., 15., 15.])
}
Array.full_like(self, /, fill_value, *, dtype=None, device=None, out=None)[source]#

ivy.Array instance method variant of ivy.full_like. This method simply wraps the function, and so the docstring for ivy.full_like also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array from which to derive the output array shape.

  • fill_value (float) – Scalar 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 self. Default: None.

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to place the created array. If device is None, the output array device must be inferred from self. 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 having the same shape as self and where every element is equal to fill_value.

Examples

With int datatype:

>>> x = ivy.array([1,2,3])
>>> fill_value = 0
>>> x.full_like(fill_value)
ivy.array([0, 0, 0])

With float datatype:

>>> fill_value = 0.000123
>>> x = ivy.array(ivy.ones(5))
>>> y = x.full_like(fill_value)
>>> print(y)
ivy.array([0.000123, 0.000123, 0.000123, 0.000123, 0.000123])

With ivy.Array input:

>>> x = ivy.array([1, 2, 3, 4, 5, 6])
>>> fill_value = 1
>>> y = x.full_like(fill_value)
>>> print(y)
ivy.array([1, 1, 1, 1, 1, 1])
Container.full_like(self, /, fill_value, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, out=None, dtype=None, device=None)[source]#

ivy.Container instance method variant of ivy.full_like. This method simply wraps the function, and so the docstring for ivy.full_like also applies to this method with minimal changes.

Parameters:
  • self (Container) – input container.

  • fill_value (Union[int, float, Container]) – Scalar fill value

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

  • dtype (Optional[Union[Dtype, NativeDtype, Container]], default: None) – output array data type. If dtype is None, the output array data type must be inferred from self. Default: None.

  • device (Optional[Union[Device, NativeDevice, Container]], default: None) – device on which to place the created array. If device is None, the output array device must be inferred from self. Default: None.

Return type:

Container

Returns:

ret – an output container having the same data type as x and whose elements, relative to x, are shifted.

Examples

With ivy.Container input:

>>> x = ivy.Container(a = ivy.array([1,2,3]) ,b = ivy.array([4,5,6]))
>>> fill_value = 10
>>> y = x.full_like(fill_value)
{
    a: ivy.array([10, 10, 10]),
    b: ivy.array([10, 10, 10])
}
>>> x = ivy.Container(a=ivy.array([1.2,2.2324,3.234]),
...                   b=ivy.array([4.123,5.23,6.23]))
>>> fill_value = 15.0
>>> y = x.full_like(fill_value)
>>> print(y)
{
    a: ivy.array([15., 15., 15.]),
    b: ivy.array([15., 15., 15.])
}