I have a folder with 1000 numpy compressed files (npz) representing the results of a data simulation. Each file has two arrays a
and b
, with same dimension, shape, data type. What I want as a final output is the element-wise mean and standard deviation arrays of a
, b
and c
(which I'm creating in the example below), taking into account all the simulation i.e.:
mean_a = np.mean(a1,a2,a3,...a1000)
std_a = np.std(a1,a2,a3...a1000)
, etc.
I've managed to get the mean values, but not using direct element-wise operation. What I'm most struggling is getting the STD. I've tried to append all the arrays into lists, but I'm getting the problem of Memory Error. Any idea of how shall I proceed? See below what I've achieved so far. Thanks in advance!!
import glob
import numpy as np
import os
simulation_runs = 10
simulation_range = np.arange(simulation_runs)
npFiles = [npFile for npFile in glob.iglob(os.path.join(outDir, "sc0*.npz"))]
a_accum = np.empty([885, 854], dtype=np.float32)
b_accum = np.empty([885, 854], dtype=np.float32)
c_accum = np.empty([885, 854], dtype=np.float32)
for run, i in enumerate(npFiles):
npData = np.load(i)
a = npData['scc']
b = npData['bcc']
c = a+b
a_accum = a + a_accum
b_accum = b + b_accum
c_accum = c + b_accum
aMean = a_accum/len(simulation_range)
bMean= b_accum/len(simulation_range)
cMean = c_accum/len(simulation_range)