Column/Rowwise Rank in Armadillo

78 views Asked by At

I have an arma::dmat X of size 4 x 5, and I need to compute the ranks columwise (or, equivalently, rowwise). That is, if X was given by

 1.7313004 -0.07725283  0.20853594 0.8234332  1.0856281
-1.5292486  1.37488968 -0.02532876 1.9258169  0.1119688 
-0.3280515 -0.26482346  1.09408275 1.5134836 -1.1991751 
-0.3365833 -0.34169977  0.94923045 0.8330554  1.7670869

then I want an arma::umat R that looks like this

4 3 3 1 2 
1 4 1 4 3
3 2 4 3 1
2 1 3 2 4

With arma::sort_index I was able to get the ranks for the matrix stacked columnwise, but this is not what I want. Of course, there is always the possibility to loop over each column and save the transformed column to a new matrix R. However, I was wondering whether there is a more elegant/more efficient solution than this.

0

There are 0 answers