Is there any equivalent of MATLAB's accumarray
?
I'm looking for an equivalent of:
accumarray(A(:),B(:),[],@mean)
where A and B are two matrix datasets.
EDIT: As asked in the comment, I will provide a bit more from the MATLAB code. As far as I understood, the first matrix contains a set of radius values (all integer values), the second contains a random pattern (here 0's and 1's) like this:
(* A(:) *)
a = Table[Round@Sqrt[x^2 + y^2], {y, -5, 5, 1.}, {x, -5, 5, 1}];
(* B(:) *)
SeedRandom[1238];
b = Table[x y, {y, RandomInteger[1, 5]}, {x, RandomInteger[1, 5]}]
Now accumarray(A(:),B(:),[],@mean)
seems to virtually collect all matrix elements of $b$ where the elements $a_{ij}$ share the same value and than the function @mean
is applied to all those virtually collected values. After this the obtained values are written in a List
containing {Value of a, mean of all values of b}
. I think this is what the code is supposed to do.
accumarray
does not seem to be part of it. $\endgroup$accumarray(A(:),B(:),[],@mean)
does? $\endgroup$