bitwise_right_shift#

ivy.bitwise_right_shift(x1, x2, /, *, out=None)[source]#

Shifts the bits of each element x1_i of the input array x1 to the right according to the respective element x2_i of the input array x2.

Note

This operation must be an arithmetic shift (i.e., sign-propagating) and thus equivalent to floor division by a power of two.

Parameters:
  • x1 (Union[int, Array, NativeArray]) – first input array. Should have an integer data type.

  • x2 (Union[int, Array, NativeArray]) – second input array. Must be compatible with x1 (see broadcasting). Should have an integer data type. Each element must be greater than or equal to 0.

  • 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 determined by type-promotion.

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:

>>> a = ivy.array([2, 9, 16, 31])
>>> b = ivy.array([0, 1, 2, 3])
>>> y = ivy.bitwise_right_shift(a, b)
>>> print(y)
ivy.array([2, 4, 4, 3])
>>> a = ivy.array([[32, 40, 55], [16, 33, 170]])
>>> b = ivy.array([5, 2, 1])
>>> y = ivy.zeros((2, 3))
>>> ivy.bitwise_right_shift(a, b, out=y)
>>> print(y)
ivy.array([[ 1., 10., 27.],
           [ 0.,  8., 85.]])
>>> a = ivy.array([[10, 64],[43, 87],[5, 37]])
>>> b = ivy.array([1, 3])
>>> ivy.bitwise_right_shift(a, b, out=a)
>>> print(a)
ivy.array([[ 5,  8],
           [21, 10],
           [ 2,  4]])

With a mix of ivy.Array and ivy.NativeArray inputs:

>>> a = ivy.array([[10, 64],[43, 87],[5, 37]])
>>> b = ivy.native_array([1, 3])
>>> y = ivy.bitwise_right_shift(a, b)
>>> print(y)
ivy.array([[ 5,  8],[21, 10],[ 2,  4]])

With one ivy.Container input:

>>> a = ivy.Container(a = ivy.array([100, 200]),
...                   b = ivy.array([125, 243]))
>>> b = ivy.array([3, 6])
>>> y = ivy.bitwise_right_shift(a, b)
>>> print(y)
{
    a: ivy.array([12, 3]),
    b: ivy.array([15, 3])
}

With multiple ivy.Container inputs:

>>> a = ivy.Container(a = ivy.array([10, 25, 42]),
...                   b = ivy.array([64, 65]),
...                   c = ivy.array([200, 225, 255]))
>>> b = ivy.Container(a = ivy.array([0, 1, 2]),
...                   b = ivy.array([6]),
...                   c = ivy.array([4, 5, 6]))
>>> y = ivy.bitwise_right_shift(a, b)
>>> print(y)
{
    a: ivy.array([10, 12, 10]),
    b: ivy.array([1, 1]),
    c: ivy.array([12, 7, 3])
}
Array.bitwise_right_shift(self, x2, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – first input array. Should have an integer or boolean data type.

  • x2 (Union[Array, NativeArray]) – second input array. Must be compatible with self (see broadcasting). 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 a data type determined by type-promotion.

Examples

>>> a = ivy.array([[2, 3, 4], [5, 10, 64]])
>>> b = ivy.array([0, 1, 2])
>>> y = a.bitwise_right_shift(b)
>>> print(y)
ivy.array([[ 2,  1,  1],
            [ 5,  5, 16]])
Container.bitwise_right_shift(self, x2, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – first input array or container. Should have an integer or boolean data type.

  • x2 (Union[Container, Array, NativeArray]) – second input array or container Must be compatible with self (see broadcasting). 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 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 element-wise results. The returned container must have a data type determined by type-promotion.

Examples

>>> a = ivy.Container(a = ivy.array([2, 3, 4]), b = ivy.array([5, 10, 64]))
>>> b = ivy.Container(a = ivy.array([0, 1, 2]), b = ivy.array([2]))
>>> y = a.bitwise_right_shift(b)
>>> print(y)
{
    a: ivy.array([2, 1, 1]),
    b: ivy.array([1, 2, 16])
}