0

l have 9000 array of arrays called my_data=(9000,). Each array is composed of a number of arrays.

len(my_data[0])=345 arrays# each array of 2000 values
len(my_data[700])=222 arrays s# each array of 2000 values

What l would like to do ?

Given two successive arrays, compute their mean and add the resulted mean vector between them.

What l have tried ?

new_data=[]
for i in np.arange(len(my_data)):
    for j in np.arange(len(my_data[i]):
         mean_arrays=np.mean(my_data[i][j],my_data[i][j+1],axis=0)
         new_data.append(my_data[i][j]) # add the first array
         new_data.append(mean_arrays) # add the mean of the two arrays
          new_data.append(my_data[i][j+1]) # add the second array
new_data=np.asarray(new_data)

Is there any efficient way to compute that efficiently in less time and in pythonic way to avoid the nested for loops ?

Thank you

6
  • 2
    Why do you have an array of arrays? It is no better than a list of arrays. Try to get all your data into a single multidimensional array. Commented Oct 28, 2018 at 14:21
  • for instace my_data[0]=[ [0.45,0.12,...,017 ],[0,0.13,...,0.78 ],...,[0.23, 0.17,...,0.98] ] Commented Oct 28, 2018 at 14:23
  • @JohnZwinck, l can't make them into a single multidimensional array because each my_data[i] is a data example which is different from my_data[j] where i !=j. So the process l defined for computing the means of two successive arrays concern each my_data[i] , but can't for example compute the mean of the last array of my_data[i] and the first array of my_data[i+1]. Hope it's clear. Commented Oct 28, 2018 at 14:29
  • I believe np.mean take one array argument only: np.mean(a, axis=None, dtype=None, out=None, keepdims=<no value>). What do you mean by np.mean(my_data[i][j],my_data[i][j+1],axis=0)? Commented Oct 29, 2018 at 5:40
  • np.mean([1,2,3],[4,5,6]) this what l mean @ZisIsNotZis Commented Oct 29, 2018 at 11:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.