I want to apply some aggregation on a numpy array.
x = np.array([ ([[ 1.87918162, 1.12919822, -1.63856741],\
[ 0.40560484, 0.96425656, 0.7847214 ],\
[-0.83472207, 0.88918246, -0.83298299],\
[-1.29211004, 0.71730071, -2.09109609],\
[-1.65800248, 0.49154087, 0.14932455]]),\
([[ 1.87918162, 1.12919822, -1.63856741],\
[-0.21786626, -0.23561859, -0.19750753],\
[-0.83472207, 0.88918246, -0.83298299],\
[-0.34967282, 0.51348973, -0.30882943],\
[ 0.35654636, -0.64453956, -1.3066075 ],\
[ 0.187328 , -1.32496725, -0.05783984]])])
print type(x)
print x[0]
print np.mean(x[0], axis=0)
print np.mean(x, axis=0)
>>> <type 'numpy.ndarray'>
>>> [[1.87918162, 1.12919822, -1.63856741], [0.40560484, 0.96425656, 0.7847214], [-0.83472207, 0.88918246, -0.83298299], [-1.29211004, 0.71730071, -2.09109609], [-1.65800248, 0.49154087, 0.14932455]]
>>> [-0.30000963 0.83829576 -0.72572011]
And the error is :
TypeError: unsupported operand type(s) for /: 'list' and 'long'
I don't understand why is it working for one row but not on the whole array. I suspect that the irregularity in the shape of the array causes the problem.
But how can I deal with that without iterate with a for loop over the array and concatenate all the results in one array ?
EDIT :
The expected result is the sum of each row vertically. So the result should be an array of dimensions (2,3).