# megengine.functional.right_shift¶

right_shift(x, y)[源代码]

Element-wise right shift.

Shifts the bits of each element $$x_i$$ of the input tensor $$x$$ to the right according to the respective element $$y_i$$ of the input tensor $$y$$.

The >> operator can be used as a shorthand for right_shift on Tensors.

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

• x – first input tensor. Should have an integer data type.

• y – second input tensor. Must be compatible with $$x$$ (see 广播机制与规则 ). Should have an integer data type. Each element must be greater than or equal to 0.

a tensor containing the result of the element-wise right shift operation. The returned tensor must have the a data type determined by 类型提升规则.

>>> F.right_shift([2, 4, 8], 1)
Tensor([1 2 4], dtype=int32, device=xpux:0)


Element-wise left shift:

>>> x = Tensor([2, 8, 24])
>>> y = Tensor([1, 2, 3])
>>> F.right_shift(x, y)
Tensor([1 2 3], dtype=int32, device=xpux:0)


>>> F.right_shift([10, 20, 40], 2)