参考MATLAB函数——atanx)和atan2x)的区别
在有的情况下只提供了atan的内置函数而没有atan2,先要判断象限再调整。
import torchimport mathpi = math.pireal = torch.tensor[ 0.12, -1.1, -0.1, 1])imag = torch.tensor[ 0.22, 1.2, -1.2, -1.2])atan = torch.atanimag/real)printatan)atan[1] = atan[1] + piatan[2] = atan[2] – piprintatan)atan2 = torch.atan2imag,real)printatan2)
output
tensor[ 1.0714, -0.8288, 1.4877, -0.8761])
tensor[ 1.0714, 2.3127, -1.6539, -0.8761])
tensor[ 1.0714, 2.3127, -1.6539, -0.8761])