2
I created a function that gives me this array as output in which each line corresponds to a point :
array([[0.57946528, 2. ],
[0.35226154, 0. ],
[0.26088698, 0. ],
[0.56560726, 1. ],
[0.41680759, 1. ],
[0.55771505, 0. ],
[0.8501109 , 0. ],
[0.76229916, 1. ],
[0.50357436, 0. ],
[0.40875861, 1. ]])
I intend to group the points by the unique value of the Y coordinate (np.Unique(y)) and calculate their mean by Y value (x_media for y = 0, x_media for y = 1,x_media for y = 2).
Thus, the new array would only have three dots (3 rows and 2 columns)
array([[mean(x, y =2) , 2. ],
[mean(x, y = 0) / , 0. ],
[mean(x, y= 1),0. ]])
I’ve thought about turning this array into a pandas dataframe but I’m looking to do this with numpy
Take a look in Soen’s reply. The package numpy-Indexed seems to do exactly what you want:
npi.group_by(a[:, 0]).mean(a[:, 1])
.– Anthony Accioly