numpy array mapping and take average
- by user566653
Dear all,
I have three array
value = np.array ([1, 3, 3, 5, 5, 7, 3])
index = np.array ([1, 1, 3, 3, 6, 6, 6])
data = np.array ([1, 2, 3, 4, 5, 6])
and want to take average for item of "value" by array "index", and assign a new array with value of "data", such as
[2, nan, 4, nan, nan, 5]
first value is the average of 1st and 2nd of "value"
second value is nan because there is not any key in "index"
third value is the average of 3rd and 4th of "value"
...
Thanks for your help!!!
Regards,
Roy