Errors with numpy unwrap when the using long arrays

自闭症网瘾萝莉.ら 提交于 2019-12-11 13:07:08

问题


I am trying to use the function numpy.unwrap to correct some phase

I have long vector with 2678399 records which contains the difference in radians between 2 angles. The array contains nan values although I think is not relevant as unwrap is applied to each record independently.

When I applied unwrap, by the 400 record generates nan values in the rest of the array

If I apply np.unwrap to just one slice of the original array works fine.

Is that a possible bug in this function?

d90dif=(df2['d90']-df2['d90avg'])*(np.pi/180)#difference between two angles in radians
df2['d90dif']=np.unwrap(d90dif.values)#unwrap to the array to create new column

just to explain the problem

d90dif[700:705]#angle difference for some records
2013-01-01 00:11:41    0.087808
2013-01-01 00:11:42    0.052901
2013-01-01 00:11:43    0.000541
2013-01-01 00:11:44    0.087808
2013-01-01 00:11:45    0.017995
dtype: float64

df2['d90dif'][700:705]#results with unwrap for these records
2013-01-01 00:11:41   NaN
2013-01-01 00:11:42   NaN
2013-01-01 00:11:43   NaN
2013-01-01 00:11:44   NaN
2013-01-01 00:11:45   NaN
Name: d90dif, dtype: float64

now I repeat the process with a small array

test=d90dif[700:705]
2013-01-01 00:11:41    0.087808
2013-01-01 00:11:42    0.052901
2013-01-01 00:11:43    0.000541
2013-01-01 00:11:44    0.087808
2013-01-01 00:11:45    0.017995
dtype: float64

unw=np.unwrap(test.values)
array([ 0.08780774,  0.05290116,  0.00054128,  0.08780774,  0.01799457])

Now it is ok. If I do it with a dataframe input in unwrap() works fine as well


回答1:


By looking at the documentation of unwrap, it seems that NaN would have an effect since the function is looking at differences of adjacent elements to detect jumps in the phase.




回答2:


It seems that the nan values play an important role

test

2013-01-01 00:11:41    0.087808
2013-01-01 00:11:42    0.052901
2013-01-01 00:11:43    0.000541
2013-01-01 00:11:44         NaN
2013-01-01 00:11:45    0.017995
dtype: float64

If there is nan in the column, from there everything becomes a nan

np.unwrap(test)

array([ 0.08780774,  0.05290116,  0.00054128,         nan,         nan])

I would say this is a bug but...



来源:https://stackoverflow.com/questions/36894896/errors-with-numpy-unwrap-when-the-using-long-arrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!