与numpy.unwrap相反 [英] Opposite of numpy.unwrap
本文介绍了与numpy.unwrap相反的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Python numpy中,有一个展开的功能:
In Python numpy, there is an unwrap function that:
通过改变绝对跳变大于不连续来解开弧度p 沿给定轴的2 * pi补码.
Unwrap radian phase p by changing absolute jumps greater than discont to their 2*pi complement along the given axis.
现在,我想执行相反的功能.如何包装一系列相位?例如.如何转换所有角度以将它们限制在-π和π之间?
Now, I'd like to do the opposite function. How can I wrap an array of phases? E.g. how to convert all angles to constraint them between -π and π?
显而易见的方法是执行以下操作:
The obvious way would be to do something like:
for i, a in enumerate(phases):
while a < pi:
a += 2 * pi
while a > pi:
a -= 2 * pi
phases[i] = a
但是有一种更简单/更快的方法吗?
but is there a simpler / faster way?
推荐答案
phases = (phases + np.pi) % (2 * np.pi) - np.pi
这篇关于与numpy.unwrap相反的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文