📜  Python| numpy numpy.ndarray.__pos__()

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

Python| numpy numpy.ndarray.__pos__()

借助Numpynumpy.ndarray.__pos__()方法,可以将数组的每个元素乘以 1。因此,结果数组的值与原始数组相同

示例 #1:
在这个例子中我们可以看到,在应用numpy.__pos__()之后,我们得到了可以和原来一样的简单数组。

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

示例 #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],
                [-6, 5, 4, 3, 2, -1]])
  
# applying numpy.__pos__() method
print(gfg.__pos__())
输出:
[[ 1  2 -3  4  5  6]
 [-6  5  4  3  2 -1]]