jax.numpy.unwrap#
- jax.numpy.unwrap(p, discont=None, axis=-1, period=6.283185307179586)[原始碼]#
解開週期性訊號。
JAX 版本的
numpy.unwrap()
。- 參數:
p (ArrayLike) – 輸入陣列
discont (ArrayLike | None) – 序列中允許的最大不連續性。預設值為
period / 2
axis (int) – 要解開的軸;預設為 -1
period (ArrayLike) – 訊號的週期,預設為 \(2\pi\)
- 傳回:
p
的解開副本。- 傳回型別:
範例
考慮一種情況,您正在透過旋轉磁碟上某個點的
x
和y
位置來測量其位置。底層變數是一個始終遞增的角度,我們將以這種方式產生它,使用度數以便於表示>>> rng = np.random.default_rng(0) >>> theta = rng.integers(0, 90, size=(20,)).cumsum() >>> theta array([ 76, 133, 179, 203, 230, 233, 239, 240, 255, 328, 386, 468, 513, 567, 654, 719, 775, 823, 873, 957])
我們對這個角度的觀察是
x
和y
座標,由這個底層角度的正弦和餘弦給出>>> x, y = jnp.sin(jnp.deg2rad(theta)), jnp.cos(jnp.deg2rad(theta))
現在,假設給定這些
x
和y
座標,我們希望恢復原始角度theta
。我們可以透過atan2()
函數來做到這一點>>> theta_out = jnp.rad2deg(jnp.atan2(x, y)).round() >>> theta_out Array([ 76., 133., 179., -157., -130., -127., -121., -120., -105., -32., 26., 108., 153., -153., -66., -1., 55., 103., 153., -123.], dtype=float32)
前幾個值與上面的輸入角度
theta
相符,但在這之後,這些值被包裹起來了,因為sin
和cos
觀察模糊了相位資訊。unwrap()
函數的目的是從這個包裹的視圖中恢復原始訊號>>> jnp.unwrap(theta_out, period=360) Array([ 76., 133., 179., 203., 230., 233., 239., 240., 255., 328., 386., 468., 513., 567., 654., 719., 775., 823., 873., 957.], dtype=float32)
它透過假設真正的底層序列在單一步驟內的不連續性不會超過
discont
(預設為period / 2
) 來做到這一點,並且當它遇到較大的不連續性時,它會將週期的因數加到資料中。對於滿足此假設的週期性訊號,unwrap()
可以恢復原始相位訊號。