python | num py . ndaarray . _ _ pos ()

哎哎哎:# t0]https://www . geeksforgeeks . org/python-num py-num py-ndaarray- _ pos _/

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

语法:n 数组。pos($self,/)

返回:+自我

示例#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__())

Output:

[ 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__())

Output:

[[ 1  2 -3  4  5  6]
 [-6  5  4  3  2 -1]]