I am trying to manipulate numpy arrays in a nested list.
I have a nested list, and in each inner list, there are several numpy arrays.
a = [
[np.random.normal(0,1,[2,3]), np.random.normal(0,1,[4,5]), np.random.normal(0,1, [9, 10])],
[np.random.normal(0,1,[2,3]), np.random.normal(0,1,[4,5]), np.random.normal(0,1, [9, 10])],
[np.random.normal(0,1,[2,3]), np.random.normal(0,1,[4,5]), np.random.normal(0,1, [9, 10])]
]
I want to element-wise compute mean of each of the numpy arrays in each list correspondingly to get a new list b, where elements are the mean of the three np.random.normal(0,1,[2,3]), the mean of the three np.random.normal(0,1,[4,5]), etc.
My initial thought was to write down a for-loop to fetch corresponding arrays and compute mean of them and then add to a list. However, this may be a bit slow when having a large number of such arrays or inner list.