Yur*_*nko 11 python numpy numpy-ufunc
(版本 1.13+)中有一个positive函数numpy,它似乎什么都不做:
In [1]: import numpy as np
In [2]: A = np.array([0, 1, -1, 1j, -1j, 1+1j, 1-1j, -1+1j, -1-1j, np.inf, -np.inf])
In [3]: A == np.positive(A)
Out[3]:
array([ True, True, True, True, True, True, True, True, True,
True, True])
Run Code Online (Sandbox Code Playgroud)
文档说: Returned array or scalar: `y = +x`
这个函数的用例是什么?
如果你有一个向量x,则np.positive(x)给你 ,+1*(x)并np.negative(x)给你-1*(x)。
np.positive([-1,0.7])
output: array([-1. , 0.7])
np.negative([-1.5,0.7])
output:array([ 1.5, -0.7])
np.positive(np.array([0, 1, -1, 1j, -1j, 1+1j, 1-1j, -1+1j, -1-1j, np.inf, -np.inf]))
output: array([ 0.+0.j, 1.+0.j, -1.+0.j, 0.+1.j, -0.-1.j, 1.+1.j,
1.-1.j, -1.+1.j, -1.-1.j, inf+0.j, -inf+0.j])
np.negative(np.array([0, 1, -1, 1j, -1j, 1+1j, 1-1j, -1+1j, -1-1j, np.inf, -np.inf]))
output: array([ -0.-0.j, -1.-0.j, 1.-0.j, -0.-1.j, 0.+1.j, -1.-1.j,
-1.+1.j, 1.-1.j, 1.+1.j, -inf-0.j, inf-0.j])
Run Code Online (Sandbox Code Playgroud)
不过,用例取决于。一旦用例它是x1 = copy(x). 它会创建一个重复的数组供您使用。
| 归档时间: |
|
| 查看次数: |
1559 次 |
| 最近记录: |