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?
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));
}