has_nans#

ivy.has_nans(x, /, *, include_infs=True)[source]#

Determine whether the array contains any nans, as well as infs or -infs if specified.

Parameters:
  • x (Union[Array, NativeArray]) – Input array.

  • include_infs (bool, default: True) – Whether to include +infinity and -infinity in the check. Default is True.

Return type:

bool

Returns:

ret – Boolean as to whether the array contains nans.

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.Array input:

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.has_nans(x)
>>> print(y)
False
>>> x = ivy.array([float('nan'), 2, 3])
>>> y = ivy.has_nans(x)
>>> print(y)
True
>>> x = ivy.array([float('inf'), 2, 3])
>>> y = ivy.has_nans(x)
>>> print(y)
True
>>> x = ivy.array([float('inf'), 2, 3])
>>> y = ivy.has_nans(x, include_infs=False)
>>> print(y)
False

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = ivy.has_nans(x)
>>> print(y)
{
    a: False,
    b: False
}
Array.has_nans(self, /, *, include_infs=True)[source]#

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

Parameters:
  • self (Array) – input array

  • include_infs (bool, default: True) – Whether to include +infinity and -infinity in the check. Default is True.

Returns:

ret – Boolean as to whether the array contains nans.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = x.has_nans()
>>> print(y)
False
Container.has_nans(self, /, *, include_infs=True, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

Determine whether arrays in the container contain any nans, as well as infs or -infs if specified.

Parameters:
  • include_infs (Union[bool, Container], default: True) – Whether to include infs and -infs in the check. Default is True.

  • 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.

Return type:

Container

Returns:

Whether the container has any nans, applied across the entire container.

Examples

>>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([float('nan'), 2]))
>>> y = x.has_nans()
>>> print(y)
{
    a: False,
    b: True
}