Been banging my head at this for a few hours and this is as clean as I can get it, but it seems it could get cleanre.
center1_x = np.mean([q[0] for q in coordinates if q[-1]==0])
center2_x = np.mean([q[0] for q in coordinates if q[-1]==1])
center3_x = np.mean([q[0] for q in coordinates if q[-1]==2])
centers_x=[center1_x,center2_x,center3_x]
coordinates is a list of sublists where each sublist contains an X coordinate at [0], y coordinate at [1] and a bin number at [-1], i.e.:
[[338.766845703125, 285.3931884765625, 0], [198.39230346679688, 184.1259307861328, 1], [356.7226867675781, 281.6376953125, 0], [200.93394470214844, 194.82655334472656, 1], [228.03591918945312, 297.79864501953125, 2], [226.06724548339844, 295.5475769042969, 2], [246.51475524902344, 280.373779296875, 2], [201.25830078125, 184.09994506835938, 1]]
Try