full_like#
- ivy.full_like(x, /, fill_value, *, dtype=None, device=None, out=None)[source]#
Return a new array filled with
fill_valueand having the sameshapeas an input arrayx.- Parameters:
x (
Union[Array,NativeArray]) – input array from which to derive the output array shape.fill_value (
Number) – Scalar fill valuedtype (
Optional[Union[Dtype,NativeDtype]], default:None) – output array data type. Ifdtypeis None, the output array data type must be inferred fromx. Default:None.device (
Optional[Union[Device,NativeDevice]], default:None) – device on which to place the created array. IfdeviceisNone, the output array device must be inferred fromx. 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:
- Returns:
ret – an array having the same shape as
xand where every element is equal tofill_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.Containerinstances in place of any of the arguments.Examples
With
intdatatype:>>> 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.NativeArrayinput:>>> 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.Containerinput:>>> 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 valuedtype (
Optional[Union[Dtype,NativeDtype]], default:None) – output array data type. Ifdtypeis None, the output array data type must be inferred fromself. Default:None.device (
Optional[Union[Device,NativeDevice]], default:None) – device on which to place the created array. IfdeviceisNone, the output array device must be inferred fromself. 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
selfand where every element is equal tofill_value.
Examples
With
intdatatype:>>> 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.Arrayinput:>>> 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 valuekey_chains (
Optional[Union[List[str],Dict[str,str],Container]], default:None) – The key-chains to apply or not apply the method to. Default isNone.to_apply (
Union[bool,Container], default:True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue.prune_unapplied (
Union[bool,Container], default:False) – Whether to prune key_chains for which the function was not applied. Default isFalse.map_sequences (
Union[bool,Container], default:False) – Whether to also map method to sequences (lists, tuples). Default isFalse.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. Ifdtypeis None, the output array data type must be inferred fromself. Default:None.device (
Optional[Union[Device,NativeDevice,Container]], default:None) – device on which to place the created array. IfdeviceisNone, the output array device must be inferred fromself. Default:None.
- Return type:
Container- Returns:
ret – an output container having the same data type as
xand whose elements, relative tox, are shifted.
Examples
With
ivy.Containerinput:>>> 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.]) }