numpy array mapping and take average
Posted
by
user566653
on Stack Overflow
See other posts from Stack Overflow
or by user566653
Published on 2011-01-13T01:47:58Z
Indexed on
2011/01/13
1:54 UTC
Read the original article
Hit count: 201
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
© Stack Overflow or respective owner