在块中迭代numpy数组



如何使用numpy.where()numpy.select()list_排列成一组数字。我想把数据分成3组,然后计算这些函数的标准差std()。因此,程序将接受457.334015,424.440002,394.795990作为要计算的标准dev的第一个值,并将接受424.440002,394.795990, 408.903992并计算标准偏差等。它会一直这样下去,直到最后到达list的末端。我希望在计算第二个块424.440002,394.795990, 408.903992之前删除第一个块457.334015,424.440002,394.795990。我想从内存中删除块,所以我没有内存错误。如果使用numpy而不使用for循环,这是否可能呢?

number = 3
list_= np.array([457.334015,424.440002,394.795990,408.903992,398.821014,402.152008,435.790985,423.204987,411.574005,
404.424988,399.519989,377.181000,375.467010,386.944000,383.614990,375.071991,359.511993,328.865997,
320.510010,330.079010,336.187012,352.940002,365.026001,361.562012,362.299011,378.549011,390.414001,
400.869995,394.773010,382.556000])

From this post:

from numpy.lib.stride_tricks import as_strided
def strided_app(a, L, S ):  # Window len = L, Stride len/stepsize = S
nrows = ((a.size-L)//S)+1
n = a.strides[0]
return np.lib.stride_tricks.as_strided(a, shape=(nrows,L), strides=(S*n,n))
list_= np.array([457.334015,424.440002,394.795990,408.903992,398.821014,402.152008,435.790985,423.204987,411.574005,
404.424988,399.519989,377.181000,375.467010,386.944000,383.614990,375.071991,359.511993,328.865997,
320.510010,330.079010,336.187012,352.940002,365.026001,361.562012,362.299011,378.549011,390.414001,
400.869995,394.773010,382.556000])
np.std(strided_app(list_, 3, 1), axis=1)

但是,这段代码并没有从数组中删除任何元素。另外,请记住,这里使用的函数带有来自numpy文档的警告!

相关内容

  • 没有找到相关文章

最新更新