本文介绍了使用长数组时,numpy的错误会自动包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试使用功能numpy.unwrap纠正某些相位

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

我有一个带有2678399个记录的长向量,其中包含2个角度之间的弧度差.该数组包含nan值,尽管我认为这无关紧要,因为将拆开独立应用于每个记录.

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.

当我应用unwrap时,由400条记录在数组的其余部分生成nan值

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

如果我仅将np.unwrap应用于原始数组的一个切片,则效果很好.

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

只是为了解释问题

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

现在我用一个小的数组重复该过程

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])

现在可以了.如果我使用unwrap()中的数据帧输入来做到这一点也很好

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

推荐答案

通过查看 unwrap的文档,似乎NaN会起作用,因为该函数正在查看相邻元素的差异以检测该阶段中的跳跃.

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.

这篇关于使用长数组时,numpy的错误会自动包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 15:45