public static DMatrixRMaj elements ( DMatrixRMaj A , BMatrixRMaj marked , DMatrixRMaj output ) { if ( A . numRows != marked . numRows || A . numCols != marked . numCols ) throw new MatrixDimensionException ( "Input matrices must have the same shape" ) ; if ( output == null ) output = new DMatrixRMaj ( 1 , 1 ) ; output . reshape ( countTrue ( marked ) , 1 ) ; int N = A . getNumElements ( ) ; int index = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( marked . data [ i ] ) { output . data [ index ++ ] = A . data [ i ] ; } } return output ; }
Returns a row matrix which contains all the elements in A which are flagged as true in marked