2015-03-25 25 views
0

The Data:我有兩個numpy數組。一個代表尖峯或峯值振幅,另一個代表以秒爲單位的相應峯值時間戳。零代表什麼都沒有,如果需要可以改爲NaN。我已經在下面複製了這些數據的一小部分。來自單獨陣列的索引元素的均值和St Dev

目標:的目標是找到基於時間不同的窗口我的振幅陣列的某些元素的平均值和標準偏差;比如說前4分鐘(0-240秒)。換句話說,我需要在我的時間數組中找到滿足該條件(0-240)的索引,然後將這些索引以輸出平均值和st dev的方式應用於振幅數組。

我嘗試:不幸的是,我是比較新的蟒蛇,並沒有能夠找到關於2D指數的操作/應用多的信息。我可以說我一直在使用numpy.where和numpy.take的非常可憐的組合。

t = [[ 111 184 221 344 366 0 0 0 0 0 0] 
[ 408 518 972 1165 1186 0 0 0 0 0 0] 
[ 208 432 1290 1321 0 0 0 0 0 0 0] 
[ 553 684 713 888 1012 1108 1134 0 0 0 0] 
[ 285 552 1159 1183 0 0 0 0 0 0 0] 
[ 304 812 852 0 0 0 0 0 0 0 0] 
[ 192 616 654 724 1143 1290 0 0 0 0 0]] 

A = [[ 0.18573314 0.52252139 0.16042311 0.21260801 0.24919374 0.    0. 
0.   0.   0.   0.  ] 
[ 0.16968141 0.18421777 0.16616463 0.19172084 0.15638406 0.   0. 
0.   0.   0.   0.  ] 
[ 0.1740181 0.24890002 0.17237853 0.20274514 0.   0.   0. 
0.   0.   0.   0.  ] 
[ 0.21144188 0.2076988 0.19915351 0.19803788 0.15826589 0.17068694 
0.15190413 0.   0.   0.   0.  ] 
[ 0.15933248 0.17080178 0.15793379 0.15461262 0.   0.   0. 
0.   0.   0.   0.  ] 
[ 0.19708434 0.1696343 0.26508617 0.   0.   0.   0. 
0.   0.   0.   0.  ] 
[ 0.2893063 0.16306161 0.1529097 0.15348586 0.24668999 0.18140199 
0.   0.   0.   0.   0.  ]] 
+0

如果下面幫你答案,它標記請爲溶液或告訴我們,如果有一些問題 – plonser 2015-03-29 13:00:18

回答

0
import numpy as np 

# get numpy.arrays in case t and A are not yet numpy.arrays 
t = np.array(t) 
A = np.array(A) 

# find the indices of the timestamps you look for 
idx = (t>0) & (t <= 240) 

# get the standard deviation and the mean 
# A[idx] consists of all those elements in A for which idx is true 
np.std(A[idx]) 
np.mean(A[idx])