📜  Python| numpy numpy.ndarray.__lshift__()

📅  最后修改于: 2022-05-13 01:55:42.259000             🧑  作者: Mango

Python| numpy numpy.ndarray.__lshift__()

Numpy numpy.ndarray.__lshift__()方法的帮助下,我们可以通过numpy.ndarray.__lshift__()方法中作为参数提供的值获得左移的元素。

示例 #1:
在这个例子中,我们可以看到每个元素都左移了作为ndarray.__lshift__()方法中的参数传递的值。

# import the important module in python
import numpy as np
     
# make an array with numpy
gfg = np.array([1, 2, 3, 4, 5])
     
# applying ndarray.__lshift__() method
print(gfg.__lshift__(2))
输出:
[ 4  8 12 16 20]

示例 #2:

# import the important module in python
import numpy as np
     
# make an array with numpy
gfg = np.array([[1, 2, 3, 4, 5],
                [6, 5, 4, 3, 2]])
     
# applying ndarray.__lshift__() method
print(gfg.__lshift__(1))
输出:
[[ 2  4  6  8 10]
 [12 10  8  6  4]]