I have an m-by-n NumPy array A, where each row represents an observation of some data. My rows are also assigned to one of c classes, and the class for each row is stored in an m-by-1 NumPy array B. I now want to compute the mean observation data M for each class. How can I do this?
For example:
A = numpy.array([[1, 2, 3], [1, 2, 3], [3, 4, 5], [4, 5, 6]])
B = numpy.array([1, 0, 0, 1]) # the first row is class 1, the second row is class 0 ...
M = # Do something
This should give me the output:
>>M
numpy.array([[2, 3, 4], [2.5, 3.5, 4.5]])
Here, row i in M is the mean for class i.
numpy? Working with data and observations is more apandasproblem; computing the means (as well other statistics) is a one-liner.