Im trying to iterate over a nested (numpy) array using np.nditer().
Converted a nested list of ints to a nested numpy array.
from numpy import mean, array, nditer
nested_list = [[1,2,3],[2,3,4],[3,4,5],[4,5,6]]
np_array = []
for i in nested_list:
a = array(nested_list)
np_array.append(a)
The above works, yielding;
[array([[1,2,3],
[2,3,4],
[3,4,5],
[4,5,6]])]
I want to calculate the mean of each nested sub-list... I have tried this but it's not working correctly.
np_mean = []
c = 0
for i in nditer(np_array):
m = mean(i)
np_mean_rep.append(m)
c += 1
print np_mean_rep
...this kinda flattens the nested array so i doesn't point to each nested sub-list but instead to each value. How would I use nditer in a way so this would work? Any pointer would be greatly appreciated!