Daniel Velden
Daniel Velden

Reputation: 179

Python Split Array use For Loop to Mean every split and put it back together

I'm coding for an Coherence project and I'm now stuck at the problem to mean my array of values in splitted parts.

So ym task would be: 1. Take my array of values (R) split it in a certain number of array parts (split by epoch) 2. enter a loop to run it automatically. 3. in the loop every value of each split part of the original array should be avaraged

Maybe the solution is damn simple, but I got stuck and I miss the wood for the forest.

Here is my approach (Rxx, epochs are defined above):

epoch_Rxx = np.array_split(Rxx,epochs)
for i in range(0,epochs):
Rxx_mean = np.zeros(epochs)
Rxx_mean[i] = np.mean(Rxx[i])

In the end I want from the e.g. Rxx = 100 values and epochs = 10

--> Rxx_mean = 10 values each to be the avaraged value of each epoch.

Greetings,

Daniel

Upvotes: 1

Views: 2399

Answers (1)

Rob
Rob

Reputation: 538

Is this what you are after?

import numpy as np

Rxx = np.arange(100)
epochs = 10
Rxx_mean = []

epoch_Rxx = np.array_split(Rxx,epochs)
for i in range(0,epochs):
  Rxx_mean.append(np.mean(epoch_Rxx[i]))

print Rxx_mean

Upvotes: 2

Related Questions