isfinite#
- ivy.isfinite(x, /, *, out=None)[source]#
Test each element
x_iof the input arrayxto determine if finite (i.e., notNaNand not equal to positive or negative infinity).- Parameters:
- Return type:
- Returns:
ret – an array containing test results. An element
out_iisTrueifx_iis finite andFalseotherwise. The returned array must have a data type ofbool.
Special Cases
For real-valued floating-point operands,
If
x_iis either+infinityor-infinity, the result isFalse.if
x_iisNaN, the result isFalse.if
x_iis a finite number, the result isTrue.
For complex floating-point operands, let
a = real(x_i),b = imag(x_i), andIf
aisNaNorbisNaN, the result isFalse.
- _ If
ais either+infinityor-infinityandbis any value, the result is
False.
If
ais any value andbis either+infinityor-infinity, the result isFalse.If
ais a finite number andbis a finite number, the result isTrue.
This method conforms to the `Array API Standard<https://data-apis.org/array-api/latest/>`_. This docstring is an extension of the docstring <https://data-apis.org/array-api/latest/ API_specification/generated/array_api.isfinite.html> _ 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
ivy.Arrayinput:>>> x = ivy.array([0, ivy.nan, -ivy.inf, float('inf')]) >>> y = ivy.isfinite(x) >>> print(y) ivy.array([ True, False, False, False])
>>> x = ivy.array([0, ivy.nan, -ivy.inf]) >>> y = ivy.zeros(3) >>> ivy.isfinite(x, out=y) >>> print(y) ivy.array([1., 0., 0.])
>>> x = ivy.array([[9, float('-0')], [ivy.nan, ivy.inf]]) >>> ivy.isfinite(x, out=x) >>> print(x) ivy.array([[1., 1.], [0., 0.]])
With
ivy.Containerinput:>>> x = ivy.Container(a=ivy.array([0., 999999999999]), ... b=ivy.array([float('-0'), ivy.nan])) >>> y = ivy.isfinite(x) >>> print(y) { a: ivy.array([True, True]), b: ivy.array([True, False]) }
- Array.isfinite(self, *, out=None)[source]#
ivy.Array instance method variant of ivy.isfinite. This method simply wraps the function, and so the docstring for ivy.isfinite also applies to this method with minimal changes.
- Parameters:
self (
Array) – input array. Should have a real-valued data type.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 containing test results. An element
out_iisTrueifself_iis finite andFalseotherwise. The returned array must have a data type ofbool.
Examples
>>> x = ivy.array([0, ivy.nan, -ivy.inf, float('inf')]) >>> y = x.isfinite() >>> print(y) ivy.array([ True, False, False, False])
- Container.isfinite(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.isfinite. This method simply wraps the function, and so the docstring for ivy.isfinite also applies to this method with minimal changes.
- Parameters:
self (
Container) – input container. Should have a real-valued data type.key_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.
- Return type:
Container- Returns:
ret – a container containing the test result. An element
out_iisTrueifself_iis finite andFalseotherwise. The returned array must have a data type ofbool.
Examples
>>> x = ivy.Container(a=ivy.array([0., 999999999999]), ... b=ivy.array([float('-0'), ivy.nan])) >>> y = x.isfinite() >>> print(y) { a: ivy.array([True, True]), b: ivy.array([True, False]) }