# 矩阵和向量

• 添加相同大小的矩阵
• 合适大小矩阵的乘法：左矩阵的列数必须等于右矩阵的行数
• 矩阵乘以列向量；根据矩阵乘法规则将行向量乘以矩阵。在这个意义上，向量是矩阵的特例
• 矩阵乘以一个数字，也就是标量

## 矩阵和向量方法列表

NumPy中的类似方法

void matrix.Eye(const int rows, const int cols, const int ndiag=0)

eye

void matrix.Identity(const int rows)

identity

void matrix.Ones(const int rows, const int cols)

ones

void matrix.Zeros(const int rows, const int cols)

zeros

void matrix.Full(const int rows, const int cols, const scalar value)

full

void matrix.Copy(const matrix a)

copy

void matrix.FromBuffer(const int rows, const int cols, const scalar array[], const int count=-1, const int offset=0)

frombuffer

void matrix.FromFile(const int rows, condt int cols, const int file_handle, const int count=-1, const int offset=0)

fromfile

void vector.FromString(const string source, const string sep=" ")

fromstring

void vector.Arange(const scalar start, const scalar stop, const scalar step=1)

arange

void matrix.Diag(const vector v, const int ndiag=0)

diag

void matrix.Tri(const int rows, const int cols, const int ndiag=0)

tri

void matrix.Tril(const int rows, const int cols, const scalar array[], const int ndiag=0)

tril

void matrix.Triu(const int rows, const int cols, const scalar array[], const int ndiag=0)

triu

void matrix.Vander(const vector v, const int cols=-1, const bool increasing=false)

vander

vector matrix.Row(const unsigned nrow)

vector matrix.Col(const unsigned ncol)

unsigned matrix.Rows()

unsigned matrix.Cols()

void matrix.Init()

matrix matrix.Transpose()

transpose

matrix matrix.Dot(const matrix b)

dot

matrix matrix.Inner(const matrix b)

inner

matrix matrix.Outer(const matrix b)

outer

matrix matrix.MatMul(const matrix b)

matmul

matrix matrix.MatrixPower(const int power)

matrix_power

matrix matrix.Kron(const matrix b)

kron

bool matrix.Cholesky(matrix& L)

cholesky

bool matrix.QR(matrix& Q, matrix& R)

qr

bool matrix.SVD(matrix& U, matrix& V, vector& singular_values)

svd

bool matrix.Eig(matrix& eigen_vectors, vector& eigen_values)

eig

bool matrix.EigH(matrix& eigen_vectors, vector& eigen_values)

eigh

bool matrix.EigVals(vector& eigen_values)

eigvals

bool matrix.EigValsH(vector& eigen_values)

eigvalsh

bool matrix.LU(matrix& L, matrix& U)

bool matrix.LUP(matrix& L, matrix& U, matrix& P)

double matrix.Norm(const norm)

norm

double matrix.Cond(const norm)

cond

vector matrix.Spectrum()

double matrix.Det()

det

int matrix.Rank()

matrix_rank

int matrix.SLogDet(int& sign)

slogdet

double matrix.Trace()

trace

vector matrix.Solve(const vector b)

solve

vector matrix.LstSq(const vector b)

lstsq

matrix matrix.Inv()

inv

matrix matrix.PInv()

pinv

int matrix.Compare(const matrix matrix_c, const double epsilon)

int matrix.Compare(const matrix matrix_c, const int digits)

int vector.Compare(const vector vector_c, const double epsilon)

int vector.Compare(const vector vector_c, const int digits)

double matrix.Flat(const ulong index)

bool matrix.Flat(const ulong index,const double value)

flat

double vector.ArgMax()

double matrix.ArgMax()

vector matrix.ArgMax(const int axis)

argmax

double vector.ArgMin()

double matrix.ArgMin()

vector matrix.ArgMin(const int axis)

argmin

double vector.Max()

double matrix.Max()

vector matrix.Max(const int axis)

max

double vector.Mean()

double matrix.Mean()

vector matrix.Mean(const int axis)

double vector.Min()

double matrix.Min()

vector matrix.Min(const int axis)

min

double vector.Sum()

double matrix.Sum()

vector matrix.Sum(const int axis)

sum

void vector.Clip(const double min_value,const double max_value)

void matrix.Clip(const double min_value,const double max_value)

clip

vector vector.CumProd()

vector matrix.CumProd()

matrix matrix.CumProd(const int axis)

cumprod

vector vector.CumSum()

vector matrix.CumSum()

matrix matrix.CumSum(const int axis)

cumsum

double vector.Prod(const double initial=1)

double matrix.Prod(const double initial=1)

vector matrix.Prod(const int axis,const double initial=1)

prod

void matrix.Reshape(const ulong rows, const ulong cols)

reshape

void matrix.Resize(const ulong rows,const ulong cols)

resize

bool matrix.SwapRows(const ulong row1, const ulong row2)

bool matrix.SwapCols(const ulong col1, const ulong col2)

double vector.Ptp()

double matrix.Ptp()

vector matrix.Ptp(const int axis)

ptp

double vector.Percentile(const int percent)

double matrix.Percentile(const int percent)

vector matrix.Percentile(const int percent,const int axis)

percentile

double vector.Quantile(const int percent)

double matrix.Quantile(const int percent)

vector matrix.Quantile(const int percent,const int axis)

quantile

double vector.Median()

double matrix.Median()

vector matrix.Median(const int axis)

median

double vector.Average()

double matrix.Average()

vector matrix.Average(const int axis)

average

double vector.Std()

double matrix.Std()

vector matrix.Std(const int axis)

std

double vector.Var()

double matrix.Var()

vector matrix.Var(const int axis)

var

double vector.CorrCoef(const vector& v)

matrix matrix.CorrCoef()

corrcoef

vector vector.Correlate(const vector& v,enum mode)

correlate

vector vector.Convolve(const vector& v, enum mode)

convolve

matrix matrix.Cov()

matrix vector.Cov(const vector& v); (resulting matrix 2 x 2)

cov