简体   繁体   中英

Constructing zero matrix in apache commons library in java

I have been scavenging thru the documentation of apache common core math library to search for this answer but havent been able to find the answer.. http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math4/linear/RealMatrix.html

How do we construct or initialize a matrix with default value.

So, I see we can do this

RealMatrix X = new BlockRealMatrix(numRows, numCols);
   or 
  double[][] matrixData = { {1d,2d,3d}, {2d,5d,3d}};
 RealMatrix m = MatrixUtils.createRealMatrix(matrixData);

But how do i construct a matrix and initialize it to all (say) 2.. (or 0 in my case), rather than explicitly creating the double[][]

Thanks

There is no single method that sets all values to a certain default value. In order to initialize the Matrix various methods might be used which all require iterating through the dimensions. setColumn and setRow allow setting the values of the entire column or row which might come close to what is searched for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM