bitwise_invert#
- ivy.bitwise_invert(x, /, *, out=None)[source]#
Inverts (flips) each bit for each element
x_iof the input arrayx.- Parameters:
- Return type:
- Returns:
ret – an array containing the element-wise results. The returned array must have the same data type as x.
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 argumentsExamples
With
ivy.Arrayinput:>>> x = ivy.array([1, 6, 9]) >>> y = ivy.bitwise_invert(x) >>> print(y) ivy.array([-2, -7, -10])
With
ivy.Containerinput:>>> x = ivy.Container(a=ivy.array([False, True, False]), ... b=ivy.array([True, True, False])) >>> y = ivy.bitwise_invert(x) >>> print(y) { a: ivy.array([True, False, True]), b: ivy.array([False, False, True]) }
With
intinput:>>> x = -8 >>> y = ivy.bitwise_invert(x) >>> print(y) ivy.array(7)
With
boolinput:>>> x = False >>> y = ivy.bitwise_invert(x) >>> print(y) True
- Array.bitwise_invert(self, *, out=None)[source]#
ivy.Array instance method variant of ivy.bitwise_invert. This method simply wraps the function, and so the docstring for ivy.bitiwse_invert also applies to this method with minimal changes.
- Parameters:
self (
Array) – input array. Should have an integer or 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 the same data type as
self.
Examples
>>> x = ivy.array([1, 6, 9]) >>> y = x.bitwise_invert() >>> print(y) ivy.array([-2, -7, -10])
>>> x = ivy.array([False, True]) >>> y = x.bitwise_invert() >>> print(y) ivy.array([True, False])
- Container.bitwise_invert(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.bitwise_invert. This method simply wraps the function, and so the docstring for ivy.bitwise_invert also applies to this method with minimal changes.
- Parameters:
self (
Container) – input container. Should have an integer or 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 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 element-wise results. The returned array must have the same data type as
self.
Examples
>>> x = ivy.Container(a = ivy.array([False, True, False]), ... b = ivy.array([True, True, False])) >>> y = x.bitwise_invert() >>> print(y) { a: ivy.array([True, False, True]), b: ivy.array([False, False, True]) }
>>> x = ivy.Container(a = ivy.array([1, 2, 3]), ... b = ivy.array([4, 5, 6])) >>> y = x.bitwise_invert() >>> print(y) { a: ivy.array([-2, -3, -4]), b: ivy.array([-5, -6, -7]) }