Getting items using an Index Matrix

9 views
Skip to first unread message

Abhishek Mishra

unread,
May 6, 2016, 3:01:43 AM5/6/16
to jblas-users
Hi,

I have a matrix X which is 5x5. I have another matrix 5x1 called Y having [ [0] , [2] , [1] , [3] , [4] ].

I would like to get those elements from X whose column index correspond to the numbers mentioned in Y.

I tried using get(DoubleMatrix rindices, DoubleMatrix cindicies) but that returns the entire column/row if its index is found in the matrix.

Right now I do it with a for loop, which takes a lot of time when X>>1,00,000.

DoubleMatrix Z = new DoubleMatrix(Y.rows, 1);

for (int j = 0; j < X,rows; j++) {

      int correctClassIndex = (int) Y.get(j, 0);

      X.put(j, 0, X.get(j, correctClass));

}


I am assuming I might have to make a nativeblas call.

Any suggestions?

Thanks,
Abhishek Mishra

Abhishek Mishra

unread,
May 6, 2016, 3:15:31 AM5/6/16
to jblas-users
Here is another workaound that I am using

public static DoubleMatrix getElementsByColumnIndex(DoubleMatrix data, DoubleMatrix Y){

DoubleMatrix X = DoubleMatrix.linspace(0, data.rows-1, data.rows);

return data.get(Y.mul(X.rows).add(X).toIntArray());

}



Thanks,
Abhi
Reply all
Reply to author
Forward
0 new messages