SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.doubles.operation
Class CreateMatrix

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.doubles.operation.CreateMatrix

public class CreateMatrix
extends java.lang.Object

This class collects the utility functions to create a new matrix/vector from existing ones.


Method Summary
static DenseMatrix cbind(Matrix... matrices)
          Take an array of matrices and combine them by columns.
static DenseMatrix cbind(MatrixList matrices)
          Take a list of matrices and combine them by columns.
static DenseMatrix cbind(Vector... vectors)
          Take an array of vectors and combine them by columns.
static DenseMatrix cbind(VectorList vectors)
          Take a list of vectors and combine them by columns.
static DenseMatrix columns(Matrix A, int[] cols)
          CreateMatrix a sub-matrix from the columns of a matrix.
static DenseMatrix columns(Matrix A, int begin, int end)
          CreateMatrix a sub-matrix from the columns of a matrix.
static Matrix copyAndReplace(Matrix toReplace, int rowFrom, int rowTo, int colFrom, int colTo, Matrix replacement)
          Deprecated. Not supported yet.
static DenseMatrix diagonalMatrix(Matrix A)
          Take the diagonal of a matrix.
static DenseMatrix rbind(Matrix... matrices)
          Take an array of matrices and combine them by rows.
static DenseMatrix rbind(MatrixList matrices)
          Take a list of matrices and combine them by rows.
static DenseMatrix rbind(Vector... vectors)
          Take an array of vectors and combine them by rows.
static DenseMatrix rbind(VectorList vectors)
          Take a list of vectors and combine them by rows.
static Matrix replace(Matrix toReplace, int rowFrom, int rowTo, int colFrom, int colTo, Matrix replacement)
          Replace a part of a matrix with a smaller matrix.
static DenseMatrix rows(Matrix A, int[] rows)
          CreateMatrix a sub-matrix from the rows of a matrix.
static DenseMatrix rows(Matrix A, int begin, int end)
          CreateMatrix a sub-matrix from the rows of a matrix.
static DenseMatrix subMatrix(Matrix A, int[] rows, int[] cols)
          CreateMatrix a sub-matrix from the intersections of rows and columns of a matrix.
static DenseMatrix subMatrix(Matrix A, int rowFrom, int rowTo, int colFrom, int colTo)
          CreateMatrix a sub-matrix from the four corners of a matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

cbind

public static DenseMatrix cbind(Vector... vectors)
Take an array of vectors and combine them by columns. The vectors must have the same length.

Parameters:
vectors - an array of vectors, e.g., v1, v2, v3, ...
Returns:
[v1 v2 v3 ...]

cbind

public static DenseMatrix cbind(VectorList vectors)
Take a list of vectors and combine them by columns. The vectors must have the same length.

Parameters:
vectors - a list of vector, e.g., {v1, v2, v3, ...}
Returns:
[v1 v2 v3 ...]

cbind

public static DenseMatrix cbind(Matrix... matrices)
Take an array of matrices and combine them by columns. The matrices must have the same number of rows.

Parameters:
matrices - an array of matrices, e.g., A1, A2, A3, ...
Returns:
[A1 A2 A3 ...]

cbind

public static DenseMatrix cbind(MatrixList matrices)
Take a list of matrices and combine them by columns. The matrices must have the same number of rows.

Parameters:
matrices - a list of matrices, e.g., {A1, A2, A3, ...}
Returns:
[A1 A2 A3 ...]

rbind

public static DenseMatrix rbind(Vector... vectors)
Take an array of vectors and combine them by rows. The vectors must have the same length.

Parameters:
vectors - an array of vector, e.g., v1, v2, v3, ...
Returns:
         | v1  |
         | v2  |
         | v3  |
         | ... |
 
Throws:
java.lang.IllegalArgumentException - if the vectors form a jagged array

rbind

public static DenseMatrix rbind(VectorList vectors)
Take a list of vectors and combine them by rows. The vectors must have the same length.

Parameters:
vectors - an array of vector, e.g., {v1, v2, v3, ...}
Returns:
         | v1  |
         | v2  |
         | v3  |
         | ... |
 

rbind

public static DenseMatrix rbind(Matrix... matrices)
Take an array of matrices and combine them by rows. The matrices must have the same number of columns.

Parameters:
matrices - a list of matrices, e.g., A1, A2, A3, ...
Returns:
         | A1  |
         | A2  |
         | A3  |
         | ... |
 

rbind

public static DenseMatrix rbind(MatrixList matrices)
Take a list of matrices and combine them by rows. The matrices must have the same number of columns.

Parameters:
matrices - a list of matrices, e.g., {A1, A2, A3, ...}
Returns:
         | A1  |
         | A2  |
         | A3  |
         | ... |
 

subMatrix

public static DenseMatrix subMatrix(Matrix A,
                                    int rowFrom,
                                    int rowTo,
                                    int colFrom,
                                    int colTo)
CreateMatrix a sub-matrix from the four corners of a matrix.

Parameters:
A - matrix
rowFrom - the beginning row index
rowTo - the ending row index
colFrom - the beginning column index
colTo - the ending column index
Returns:
A[rowFrom:rowTo, colFrom:colTo]

subMatrix

public static DenseMatrix subMatrix(Matrix A,
                                    int[] rows,
                                    int[] cols)
CreateMatrix a sub-matrix from the intersections of rows and columns of a matrix.

Parameters:
A - a matrix
rows - the rows to be extracted
cols - the columns to be extracted
Returns:
A[rows, cols]

rows

public static DenseMatrix rows(Matrix A,
                               int[] rows)
CreateMatrix a sub-matrix from the rows of a matrix.

Parameters:
A - a matrix
rows - the rows to be extracted
Returns:
a matrix whose rows are from A

rows

public static DenseMatrix rows(Matrix A,
                               int begin,
                               int end)
CreateMatrix a sub-matrix from the rows of a matrix.

Parameters:
A - a matrix
begin - the beginning row index (counting from 1)
end - the ending row index (counting from 1)
Returns:
a matrix whose rows are from A

columns

public static DenseMatrix columns(Matrix A,
                                  int[] cols)
CreateMatrix a sub-matrix from the columns of a matrix.

Parameters:
A - a matrix
cols - the columns to be extracted
Returns:
a matrix whose columns are from A

columns

public static DenseMatrix columns(Matrix A,
                                  int begin,
                                  int end)
CreateMatrix a sub-matrix from the columns of a matrix.

Parameters:
A - a matrix
begin - the beginning column index (counting from 1)
end - the ending column index (counting from 1)
Returns:
a matrix whose columns are from A

replace

public static Matrix replace(Matrix toReplace,
                             int rowFrom,
                             int rowTo,
                             int colFrom,
                             int colTo,
                             Matrix replacement)
Replace a part of a matrix with a smaller matrix. The replaced matrix changes afterward (for performance reason in case of a big matrix).

This method is best NOT to apply to SymmetricMatrix because it is hard to ensure the symmetry property after replacement.

Note that no new DoubleMatrixAccessor instance is created.

Parameters:
toReplace - matrix whose part is to be replaced
rowFrom - the beginning row index
rowTo - the ending row index
colFrom - the beginning column index
colTo - the ending column index
replacement - matrix to be inserted into 'toReplace'
Returns:
the toReplace matrix, which has changed

copyAndReplace

@Deprecated
public static Matrix copyAndReplace(Matrix toReplace,
                                               int rowFrom,
                                               int rowTo,
                                               int colFrom,
                                               int colTo,
                                               Matrix replacement)
Deprecated. Not supported yet.

Make a copy of a matrix and then replace a part of the copy.

The two input matrices are not changed.

This method is best NOT to apply to SymmetricMatrix because it is hard to ensure the symmetry property after replacement.

Parameters:
toReplace - matrix whose part is to be replaced
rowFrom - the beginning row index
rowTo - the ending row index
colFrom - the beginning column index
colTo - the ending column index
replacement - matrix to be inserted into toReplace
Returns:
a new instance of DenseMatrix whose entries are the same as toReplace, except for the replacement part

diagonalMatrix

public static DenseMatrix diagonalMatrix(Matrix A)
Take the diagonal of a matrix.

Parameters:
A - a matrix
Returns:
a diagonal matrix whose diagonal entries are Ai, zeros elsewhere
Throws:
java.lang.IllegalArgumentException - if A is not square

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.