Skip to content

4 Get Stats About Matrix

Süleyman Özarslan edited this page Sep 17, 2022 · 1 revision

Shape (Matrix Size)

func (matrix Matrix) Shape() map[string]int

The Shape function is used to get the number of rows and columns of a matrix. It returns a map with the values of "rows" and "cols".

mx := matrix.Matrix{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}
rowNumber := mx.Shape()["rows"]
colNumber := mx.Shape()["cols"]

Sum

func (matrix Matrix) Sum() float64

Sum function returns the sum of the values in the matrix.

mx := matrix.Matrix{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}
sum := mx.Sum() //45

Mean

func (matrix Matrix) Mean() float64

Mean returns the mean of the values in the matrix.

mx := matrix.Matrix{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}
mean := mx.Mean() //5

Variance

func (matrix Matrix) Variance() float64

Variance function returns the variance of the values in the matrix.

mx := matrix.Matrix{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}
variance := mx.Variance()

Standard Deviation

func (matrix Matrix) Std() float64

Std function returns the standard deviation of the values in the matrix.

mx := matrix.Matrix{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}
sd := mx.Std()

Max

func (matrix Matrix) Max() float64

Max function returns the max value of matrix

mx := matrix.Matrix{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}
max := mx.Max()

Min

func (matrix Matrix) Min() float64

Min function returns the min value of matrix

mx := matrix.Matrix{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}
min := mx.Min()

Determinant

func (matrix Matrix) Det() float64

Det function returns determinant of the matrix

mx := matrix.Matrix{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}
det := mx.Det()

Clone this wiki locally