Pregunta

How can I transpose an array using functions from libraries? I have downloaded and used the library Colt from here: http://acs.lbl.gov/software/colt/api/index.html. I tried :

DoubleMatrix1D array;
array = new DenseDoubleMatrix1D(4);
for (int i=0; i<4; i++)
    array.set(i,i);
DoubleMatrix1D transpose = array.viewDice();

but it doesn't work, as I get the error:

The method viewDice() is undefined for the type DoubleMatrix1D

Any ideas?

¿Fue útil?

Solución

1D matrices don't contain any information about how they are oriented. So you would need to supply this information in order to transpose it. For example, if you are using a row vector, you have a 1xm matrix, so you would need an mx1 column vector to contain the transpose.

Try this:

DoubleMatrix2D transpose = new DenseDoubleMatrix2D(4,1);
for (int i=0; i<4; i++) {
    transpose.setQuick(i,0,array.getQuick(i));
}

If instead you have a column vector, the transpose would be a row vector:

DoubleMatrix2D transpose = new DenseDoubleMatrix2D(1,4);
for (int i=0; i<4; i++) {
    transpose.setQuick(0,i,array.getQuick(i));
}

Otros consejos

This means that in the class DoubleMatrix1D the method viewDice() doesnt exists! So you barely can use it :).

According to documentation, you can use this :

 double[]   toArray() 
          Constructs and returns a 1-dimensional array containing the cell values.

Or maybe this :

 DoubleMatrix1D copy() 
          Constructs and returns a deep copy of the receiver.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top