code: 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;
      }
docs: Returns a row matrix which contains all the elements in A which are flagged as true in 'marked'
  
  @param A Input matrix
  @param marked Input matrix marking elements in A
  @param output Storage for output row vector. Can be null.  Will be reshaped.
  @return Row vector with marked elements