![](/img/trans.png)
[英]Why are the class __dict__ and __weakref__ never re-defined in Python?
[英]Why does this 1-D array in python get altered / re-defined while being autocorrelated?
在python中,我定義了一個1-D數組系數 ,如下所示:
coef = np.ones(frame_num-1)
for i in range(1,frame_num):
coef[i-1] = np.corrcoef(data[:,i],data[:,i-1])[0,1]
np.savetxt('serial_corr_results/coef_rest.txt', coef)
現在,我想對其進行自相關,為此,我在另一篇文章中使用了deltap發布的代碼:
timeseries = (coef)
#mean = np.mean(timeseries)
timeseries -= np.mean(timeseries)
autocorr_f = np.correlate(timeseries, timeseries, mode='full')
temp = autocorr_f[autocorr_f.size/2:]/autocorr_f[autocorr_f.size/2]
自相關工作正常,但是,當我現在想要繪制或使用原始系數時,這些值已更改為timeseries-= np.mean(timeseries)的值。
為什么在這里更改了原始數組系數,如何防止其被更改? 我需要在腳本中進一步進行其他操作。
另外,操作-=到底在做什么? 我試圖用谷歌搜索,但是沒有找到。 謝謝!
NumPy數組是可變的,例如
timeseries = coef # timeseries and coef point to same data
timeseries[:] = 0
會將timeseries
和coef
都設置為零。
如果你這樣做
timeseries = coef.copy() # timeseries is a copy of coef with its own data
timeseries[:] = 0
相反, coef
將保持不變。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.