Generate a matrix with random values.
@param nRows number of matrix's rows.
@param nColumns number of matrix's columns.
@return Matrix that consists of random values.
496746
private Matrix<Double> generateRandomMatrix(final int nRows, final int nColumns) {
    final List<List<Double>> rows = new ArrayList<>(nRows);
    final Random random = new Random();
    for (int i = 0; i < nRows; i++) {
      final List<Double> row = new ArrayList<>(nColumns);
      for (int j = 0; j < nColumns; j++) {
        row.add(random.nextDouble());
      }
      rows.add(row);
    }
    return new RowMatrix(rows);
  }
770288
@Override
    public INDArray randn(long rows, long columns) {
        return randn(new long[] {rows, columns}, System.currentTimeMillis());
    }
610739
def randmatrix(m, n, random_seed=None):
    """"""
    val = np.sqrt(6.0 / (m + n))
    np.random.seed(random_seed)
    return np.random.uniform(-val, val, size=(m, n))
190025
function () {
      var rowCounts = new Uint32Array(nrows);
      var columnCounts = new Uint32Array(ncols);
      for (var i = 0; i < nrows; i++) {
        var obj = matrix[i];
        if (obj.values != null) {
          // trim to size
          var values = new Uint16Array(obj.length);
          var indices = new Uint32Array(obj.length);
          values.set(obj.values.slice(0, obj.length));
          indices.set(obj.indices.slice(0, obj.length));
          matrix[i] = {values: values, indices: indices};
          rowCounts[i] = values.length;
          for (var j = 0; j < obj.length; j++) {
            columnCounts[indices[j]] += 1;
          }
        }
      }
      dataset = new morpheus.Dataset({
        rows: nrows, columns: ncols, name: morpheus.Util.getBaseFileName(morpheus.Util
          .getFileName(fileOrUrl)), array: matrix, dataType: dataType, defaultValue: 0
      });

      dataset.getRowMetadata().add('count>0').array = rowCounts;
      dataset.getColumnMetadata().add('count>0').array = columnCounts;
    }
827941
public static LinearSolverDense<DMatrixRMaj> general(int numRows , int numCols ) {
        if( numRows == numCols )
            return linear(numRows);
        else
            return leastSquares(numRows,numCols);
    }
1091011
public DMatrixRMaj readDDRM(int numRows, int numCols) throws IOException {

        DMatrixRMaj A = new DMatrixRMaj(numRows,numCols);

        for( int i = 0; i < numRows; i++ ) {
            List<String> words = extractWords();
            if( words == null )
                throw new IOException("Too few rows found. expected "+numRows+" actual "+i);

            if( words.size() != numCols )
                throw new IOException("Unexpected number of words in column. Found "+words.size()+" expected "+numCols);
            for( int j = 0; j < numCols; j++ ) {
                A.set(i,j,Double.parseDouble(words.get(j)));
            }
        }

        return A;
    }
585817
public static DMatrixRMaj[] columnsToVector(DMatrixRMaj A, DMatrixRMaj[] v)
    {
        DMatrixRMaj[]ret;
        if( v == null || v.length < A.numCols ) {
            ret = new DMatrixRMaj[ A.numCols ];
        } else {
            ret = v;
        }

        for( int i = 0; i < ret.length; i++ ) {
            if( ret[i] == null ) {
                ret[i] = new DMatrixRMaj(A.numRows,1);
            } else {
                ret[i].reshape(A.numRows,1, false);
            }

            DMatrixRMaj u = ret[i];

            for( int j = 0; j < A.numRows; j++ ) {
                u.set(j,0, A.get(j,i));
            }
        }

        return ret;
    }
491953
public static RowMajorSparseMatrix random(int rows, int columns, double density, Random random) {
        return CRSMatrix.random(rows, columns, density, random);
    }
433269
public static double[][] matrixFromRange (double[] lower, double[] upper, int rows) {
        // Get the number of columns:
        final int cols = lower.length;

        // Initialize the return value:
        final double[][] matrix = new double[rows][cols];

        // Iterate over columns and fill the array:
        for (int col = 0; col < cols; col++) {
            // Get the sequence:
            final double[] sequence = DMatrixUtils.sequence(lower[col], upper[col], rows);

            // Assign to each row in the column:
            for (int row = 0; row < sequence.length; row++) {
                matrix[row][col] = sequence[row];
            }
        }

        // Done, return the populated matrix:
        return matrix;
    }
1152201
public Matrix transpose()
    {
        double tv[][] = new double[nCols][nRows];  // transposed values

        // Set the values of the transpose.
        for (int r = 0; r < nRows; ++r) {
            for (int c = 0; c < nCols; ++c) {
                tv[c][r] = values[r][c];
            }
        }

        return new Matrix(tv);
    }
1015265
public Table last(int nRows) {
        int newRowCount = Math.min(nRows, rowCount());
        return inRange(rowCount() - newRowCount, rowCount());
    }
1212149
public static AbstractMatrix getInstance(int rows, Object values, Class<?> cls)
    {
        int length = Array.getLength(values);
        if (length % rows != 0)
        {
            throw new IllegalArgumentException("not full rows");
        }
        return new AbstractMatrix(rows, copyOf(values, cls));
    }
618374
public static double[][] getNcsAsArray(Matrix4d[] ncsOperators) {
		if(ncsOperators==null){
			return new double[0][0];
		}
		double[][] outList = new double[ncsOperators.length][16];
		for(int i=0; i<ncsOperators.length;i++){
			outList[i] = convertToDoubleArray(ncsOperators[i]);
		}
		return outList;
	}
1042221
@Override
    public INDArray randn(long rows, long columns, org.nd4j.linalg.api.rng.Random r) {
        return randn(new long[] {rows, columns}, r);
    }
85351
public static Matrix random(int M, int N) {
        Matrix A = new Matrix(M, N);
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                A.data[i][j] = Math.random();
            }
        }
        return A;
    }
1217811
public static Basic1DMatrix random(int rows, int columns, Random random) {
        double[] array = new double[rows * columns];

        for (int i = 0; i < rows * columns; i++) {
            array[i] = random.nextDouble();
        }

        return new Basic1DMatrix(rows, columns, array);
    }
1058364
private void set(Matrix m)
    {
        this.nRows  = 1;
        this.nCols  = m.nCols;
        this.values = m.values;
    }