I have 'n' numpy arrays each with shape (128,) How to get an average numpy array of shape (128,) for the list of numpy arrays. I have seen the documentation of numpy's average() and mean() which describes that the average is calculated for all the elements in a single numpy array rather than multiple or list of numpy arrays. Example
numpyArrayList = [ar1,ar2,ar3,ar4...arn]
avgNumpyArray = avg(numpyArrayList)
avgNumpyArray.shape
should give result as (128,) and this array should contain the average of all the numpy arrays
Thanks in advance
I would use np.mean([ar1,ar2,ar3,ar4...arn], axis=0)
.
You can achieve this by using the following code
ar = [ar1,ar2,ar3,...,arn]
r = np.mean(ar)
for axis=0 use following
r = np.mean(ar, axis=0)
for axis=1 use following
r = np.mean(ar, axis=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With