matrix
import matrixFunctions
Section titled “Functions”| Function | Signature | Description |
|---|---|---|
zeros | (Int, Int) -> Matrix | Create a zero-filled matrix. |
ones | (Int, Int) -> Matrix | Create a matrix filled with ones. |
shape | (Matrix) -> (Int, Int) | Get the (rows, cols) shape of a matrix. |
transpose | (Matrix) -> Matrix | Transpose a matrix. |
from_lists | (List[List[Float]]) -> Matrix | Create a matrix from a list of row lists. |
to_lists | (Matrix) -> List[List[Float]] | Convert a matrix to a list of row lists. |
get | (Matrix, Int, Int) -> Float | Get element at (row, col). |
rows | (Matrix) -> Int | Get the number of rows. |
cols | (Matrix) -> Int | Get the number of columns. |
add | (Matrix, Matrix) -> Matrix | Element-wise addition of two matrices. |
mul | (Matrix, Matrix) -> Matrix | Matrix multiplication. |
scale | (Matrix, Float) -> Matrix | Multiply all elements by a scalar. |
map | (Matrix, fn(Float) -> Float) -> Matrix | Apply a function to every element. |
Reference
Section titled “Reference”matrix.zeros(rows: Int, cols: Int) -> Matrix
Section titled “matrix.zeros(rows: Int, cols: Int) -> Matrix”Create a zero-filled matrix.
matrix.zeros(3, 4)matrix.ones(rows: Int, cols: Int) -> Matrix
Section titled “matrix.ones(rows: Int, cols: Int) -> Matrix”Create a matrix filled with ones.
matrix.ones(3, 4)matrix.shape(m: Matrix) -> (Int, Int)
Section titled “matrix.shape(m: Matrix) -> (Int, Int)”Get the (rows, cols) shape of a matrix.
matrix.shape(m) // => (3, 4)matrix.transpose(m: Matrix) -> Matrix
Section titled “matrix.transpose(m: Matrix) -> Matrix”Transpose a matrix.
matrix.transpose(m)matrix.from_lists(rows: List[List[Float]]) -> Matrix
Section titled “matrix.from_lists(rows: List[List[Float]]) -> Matrix”Create a matrix from a list of row lists.
matrix.from_lists([[1.0, 2.0], [3.0, 4.0]])matrix.to_lists(m: Matrix) -> List[List[Float]]
Section titled “matrix.to_lists(m: Matrix) -> List[List[Float]]”Convert a matrix to a list of row lists.
matrix.to_lists(m) // => [[1.0, 2.0], [3.0, 4.0]]matrix.get(m: Matrix, row: Int, col: Int) -> Float
Section titled “matrix.get(m: Matrix, row: Int, col: Int) -> Float”Get element at (row, col).
matrix.get(m, 0, 1) // => 2.0matrix.rows(m: Matrix) -> Int
Section titled “matrix.rows(m: Matrix) -> Int”Get the number of rows.
matrix.rows(m) // => 3matrix.cols(m: Matrix) -> Int
Section titled “matrix.cols(m: Matrix) -> Int”Get the number of columns.
matrix.cols(m) // => 4matrix.add(a: Matrix, b: Matrix) -> Matrix
Section titled “matrix.add(a: Matrix, b: Matrix) -> Matrix”Element-wise addition of two matrices.
matrix.add(a, b)matrix.mul(a: Matrix, b: Matrix) -> Matrix
Section titled “matrix.mul(a: Matrix, b: Matrix) -> Matrix”Matrix multiplication.
matrix.mul(a, b)matrix.scale(m: Matrix, s: Float) -> Matrix
Section titled “matrix.scale(m: Matrix, s: Float) -> Matrix”Multiply all elements by a scalar.
matrix.scale(m, 2.0)matrix.map(m: Matrix, f: fn(Float) -> Float) -> Matrix
Section titled “matrix.map(m: Matrix, f: fn(Float) -> Float) -> Matrix”Apply a function to every element.
matrix.map(m, (x) => x * x)