logical_not#

ivy.logical_not(x, /, *, out=None)[source]#

Compute the logical NOT for each element x_i of the input array x.

Note

While this specification recommends that this function only accept input arrays having a boolean data type, specification-compliant array libraries may choose to accept input arrays having numeric data types. If non-boolean data types are supported, zeros must be considered the equivalent of False, while non-zeros must be considered the equivalent of True.

Special cases

For this particular case,

  • If x_i is NaN, the result is False.

  • If x_i is -0, the result is True.

  • If x_i is -infinity, the result is False.

  • If x_i is +infinity, the result is False.

Parameters:
  • x (Union[Array, NativeArray]) – input array. Should have a boolean 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 the element-wise results. The returned array must have a data type of bool.

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

>>> x=ivy.array([1,0,1,1,0])
>>> y=ivy.logical_not(x)
>>> print(y)
ivy.array([False, True, False, False,  True])
>>> x=ivy.array([2,0,3,5])
>>> y=ivy.logical_not(x)
>>> print(y)
ivy.array([False, True, False, False])
>>> x=ivy.native_array([1,0,6,5])
>>> y=ivy.logical_not(x)
>>> print(y)
ivy.array([False, True, False, False])

With ivy.Container input:

>>> x=ivy.Container(a=ivy.array([1,0,1,1]), b=ivy.array([1,0,8,9]))
>>> y=ivy.logical_not(x)
>>> print(y)
{
    a: ivy.array([False, True, False, False]),
    b: ivy.array([False, True, False, False])
}
>>> x=ivy.Container(a=ivy.array([1,0,1,0]), b=ivy.native_array([5,2,0,3]))
>>> y=ivy.logical_not(x)
>>> print(y)
{
    a: ivy.array([False, True, False, True]),
    b: ivy.array([False, False, True, False])
}
Array.logical_not(self, *, out=None)[source]#

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

Parameters:
  • self (Array) – input array. Should have a boolean data type.

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

Return type:

Array

Returns:

ret – an array containing the element-wise results. The returned array must have a data type of bool.

Examples

With ivy.Array input:

>>> x=ivy.array([0,1,1,0])
>>> x.logical_not()
ivy.array([ True, False, False,  True])
>>> x=ivy.array([2,0,3,9])
>>> x.logical_not()
ivy.array([False,  True, False, False])
Container.logical_not(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – input container. Should have a boolean 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 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.

Return type:

Container

Returns:

ret – a container containing the evaluated result for each element in self. The returned container must have a data type of bool.

Examples

Using ‘ivy.Container’ instance

>>> x=ivy.Container(a=ivy.array([1,0,0,1]), b=ivy.array([3,1,7,0]))
>>> y = x.logical_not()
>>> print(y)
{
    a: ivy.array([False, True, True, False]),
    b: ivy.array([False, False, False, True])
}
>>> x=ivy.Container(a=ivy.array([1,0,1,0]), b=ivy.native_array([5,2,0,3]))
>>> y = x.logical_not()
>>> print(y)
{
    a: ivy.array([False, True, False, True]),
    b: ivy.array([False, False, True, False])
}