Creates a random {@link ColumnMajorSparseMatrix} of the given shape:
{@code rows} x {@code columns}.
496962
public static ColumnMajorSparseMatrix random(int rows, int columns, double density, Random random) {
        return CCSMatrix.random(rows, columns, density, random);
    }
117586
public static void setRandomB(BMatrixRMaj mat , Random rand )
    {
        boolean d[] = mat.data;
        int size = mat.getNumElements();


        for( int i = 0; i < size; i++ ) {
            d[i] = rand.nextBoolean();
        }
    }
1353440
public static Basic2DMatrix random(int rows, int columns, Random random) {
        double[][] array = new double[rows][columns];

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

        return new Basic2DMatrix(array);
    }
964574
public static INDArray generate(long[] shape, char order, Values values){
        switch (values){
            case RANDOM_UNIFORM:
                return Nd4j.rand(Nd4j.createUninitialized(shape,order));
            case RANDOM_NORMAL:
                return Nd4j.randn(Nd4j.createUninitialized(shape,order));
            case ONE_HOT:
                Random r = new Random(Nd4j.getRandom().nextLong());
                INDArray out = Nd4j.create(shape,order);
                if(shape.length == 1){
                    out.putScalar(r.nextInt((int) shape[0]), 1.0);
                } else if(shape.length == 2){
                    for( int i=0; i<shape[0]; i++ ){
                        out.putScalar(i, r.nextInt((int) shape[1]), 1.0);
                    }
                } else if(shape.length == 3){
                    for( int i=0; i<shape[0]; i++ ){
                        for(int j=0; j<shape[2]; j++ ){
                            out.putScalar(i, r.nextInt((int) shape[1]), j, 1.0);
                        }
                    }
                } else if(shape.length == 4){
                    for( int i=0; i<shape[0]; i++ ){
                        for(int j=0; j<shape[2]; j++ ){
                            for(int k=0; k<shape[3]; k++ ) {
                                out.putScalar(i, r.nextInt((int) shape[1]), j, k, 1.0);
                            }
                        }
                    }
                } else if(shape.length == 5){
                    for( int i=0; i<shape[0]; i++ ){
                        for(int j=0; j<shape[2]; j++ ){
                            for(int k=0; k<shape[3]; k++ ) {
                                for( int l=0; l<shape[4]; l++ ) {
                                    out.putScalar(new int[]{i, r.nextInt((int) shape[1]), j, k, l}, 1.0);
                                }
                            }
                        }
                    }
                } else {
                    throw new RuntimeException("Not supported: rank 6+ arrays. Shape: " + Arrays.toString(shape));
                }
                return out;
            case ZEROS:
                return Nd4j.create(shape,order);
            case ONES:
                return Nd4j.createUninitialized(shape,order).assign(1.0);
            case BINARY:
                return Nd4j.getExecutioner().exec(new BernoulliDistribution(Nd4j.createUninitialized(shape, order), 0.5));
            case INTEGER_0_10:
                return Transforms.floor(Nd4j.rand(shape).muli(10), false);
            case INTEGER_0_100:
                return Transforms.floor(Nd4j.rand(shape).muli(100), false);
            case INTEGER_0_1000:
                return Transforms.floor(Nd4j.rand(shape).muli(1000), false);
            case INTEGER_0_10000:
                return Transforms.floor(Nd4j.rand(shape).muli(10000), false);
            case INTEGER_0_100000:
                return Transforms.floor(Nd4j.rand(shape).muli(100000), false);
            default:
                throw new RuntimeException("Unknown enum value: " + values);

        }
    }
1241304
public Matrix createSparseMatrix() {

        Matrix m = Matrices.create(matrix_row_map.size(), matrix_column_map.size(), false);
        for (int row_num = 0; row_num < matrix_row_map.size(); row_num++) { // for each pattern
            String p = matrix_row_map.get(new Integer(row_num));
            String[] p_sp = p.split(":");
            String a = p_sp[0];
            String b = p_sp[1];
            for (int col_num = 0; col_num < matrix_column_map.size(); col_num++) { // for each phrase
                InterveningWordsPattern col_pattern = matrix_column_map.get(new Integer(col_num));
                String pattern = col_pattern.getPattern();
                String comb_patterns;
                if (col_pattern.getReverse()) { //if the column is a reverse pattern...word2 P word1
                    comb_patterns = ".*\\s" + b + pattern + a + "\\s.*";
                } else {
                    comb_patterns = ".*\\s" + a + pattern + b + "\\s.*";
                }
                try {
                    m.set(row_num, col_num, (double)countWildcardPhraseFrequencies(new File(DATA_DIR), comb_patterns));
                } catch (Exception e) {
                    System.err.println("could not perform wildcard search");
                }
            }
        }
        System.err.println("\nCompleted matrix generation.");
        //System.err.println("Number of rows: " + m.rows());
        //System.err.println("Number of cols: " + m.columns());
        return m;
    }
1037522
public static Matrix random(int rows, int columns, Random random) {
        return DenseMatrix.random(rows, columns, random);
    }
460777
public static ColumnMajorSparseMatrix from1DArray(int rows, int columns, double[] array) {
        return CCSMatrix.from1DArray(rows, columns, array);
    }
396986
public static SparseMatrix random(int rows, int columns, double density, Random random) {
        return CRSMatrix.random(rows, columns, density, random);
    }
1054901
public static FloatMatrix centerColumns(FloatMatrix x) {
                FloatMatrix temp = new FloatMatrix(x.rows);
		for (int c = 0; c < x.columns; c++)
			x.putColumn(c, center(x.getColumn(c, temp)));
		return x;
	}
1182024
public static WritableRaster createWritableRasterFromMatrix( float[][] matrix, boolean matrixIsRowCol ) {
        int height = matrix.length;
        int width = matrix[0].length;
        if (!matrixIsRowCol) {
            int tmp = height;
            height = width;
            width = tmp;
        }
        WritableRaster writableRaster = createWritableRaster(width, height, null, null, null);

        WritableRandomIter randomIter = RandomIterFactory.createWritable(writableRaster, null);
        for( int x = 0; x < width; x++ ) {
            for( int y = 0; y < height; y++ ) {
                if (matrixIsRowCol) {
                    randomIter.setSample(x, y, 0, matrix[y][x]);
                } else {
                    randomIter.setSample(x, y, 0, matrix[x][y]);
                }
            }
        }
        randomIter.done();

        return writableRaster;
    }
1358643
public static INDArray toMatrix(List<Row> rows) {
        INDArray ret = Nd4j.create(rows.size(), rows.get(0).size());
        for (int i = 0; i < ret.rows(); i++) {
            for (int j = 0; j < ret.columns(); j++) {
                ret.putScalar(i, j, rows.get(i).getDouble(j));
            }
        }
        return ret;
    }
229448
public static Object[][] matrixTransform(Object[][] datas) {
        if (datas.length == 0 || datas[0].length == 0) {
            return datas;
        }
        int column = datas.length;
        int row = datas[0].length;

        Object[][] newData = new Object[row][column];

        for (int i = 0; i < row; i++) {
            Object[] list = new Object[column];
            for (int j = 0; j < column; j++) {
                list[j] = datas[j][i];
            }
            newData[i] = list;
        }
        return newData;
    }
412239
function _Matrix(numRows, numColumns, data) {
  if(!Number.isInteger(numRows))
    throw new TypeError("/numRows/ must be an integer.");
  if(!Number.isInteger(numColumns))
      throw new TypeError("/numColumns/ must be an integer.");

  var _values;
  var _numValues = numRows * numColumns;
  if (!data || data === undefined)
    _values = [];
  else if (!util.isNumberArray(data))
    throw new TypeError('Invalid values for vector.');
  else
    _values = data;

  // Make sure the matrix has numRows * numColumns values
  if (_values.length < _numValues) {
    var zeros = Array(_numValues - _values.length).fill(0);
    _values = _values.concat(zeros);
  } else if (_values.length > _numValues) {
    _values = _values.slice(0, _numValues);
  }

  var size = {"rows": numRows, "columns": numColumns};
  readonly(this, "size", size);
  readonly(this, "values", _values);
  readonly(this, "rows", _getRows(this));
  readonly(this, "columns", _getColumns(this));
}
738947
public static DMatrixSparseCSC concatRows(DMatrixSparseCSC top , DMatrixSparseCSC bottom ,
                                              @Nullable DMatrixSparseCSC out )
    {
        if( top.numCols != bottom.numCols )
            throw new MatrixDimensionException("Number of columns must match. "+stringShapes(top,bottom));
        if( out == null )
            out = new DMatrixSparseCSC(0,0,0);

        out.reshape(top.numRows+bottom.numRows,top.numCols,top.nz_length+bottom.nz_length);
        out.nz_length = top.nz_length+bottom.nz_length;

        int index = 0;
        for (int i = 0; i < top.numCols; i++) {
            int top0 = top.col_idx[i];
            int top1 = top.col_idx[i+1];

            int bot0 = bottom.col_idx[i];
            int bot1 = bottom.col_idx[i+1];

            int out0 = out.col_idx[i];
            int out1 = out0 + top1-top0 + bot1-bot0;
            out.col_idx[i+1] = out1;

            for (int j = top0; j < top1; j++ , index++) {
                out.nz_values[index] = top.nz_values[j];
                out.nz_rows[index] = top.nz_rows[j];
            }
            for (int j = bot0; j < bot1; j++ , index++) {
                out.nz_values[index] = bottom.nz_values[j];
                out.nz_rows[index] = top.numRows + bottom.nz_rows[j];
            }
        }
        out.indicesSorted = false;

        return out;
    }
995042
public static RealMatrix shuffleRows (RealMatrix matrix, RandomGenerator randomGenerator) {
        // Create an index vector to be shuffled:
        int[] index = MathArrays.sequence(matrix.getRowDimension(), 0, 1);
        MathArrays.shuffle(index, randomGenerator);

        // Create a new matrix:
        RealMatrix retval = MatrixUtils.createRealMatrix(matrix.getRowDimension(), matrix.getColumnDimension());

        // Populate:
        for (int row = 0; row < index.length; row++) {
            retval.setRowVector(row, matrix.getRowVector(index[row]));
        }

        // Done, return:
        return retval;
    }
321835
public static DenseMatrix from1DArray(int rows, int columns, double[] array) {
        return Basic1DMatrix.from1DArray(rows, columns, array);
    }
443915
public static void printMatrix(int rows, int cols, Matrix m) {
        for(int col_num = 0; col_num < cols; col_num++) {
            for (int row_num = 0; row_num < rows; row_num++) {
                System.out.print(m.get(row_num,col_num) + " ");
            }
            System.out.print("\n");
        }
        System.out.print("\n");
    }