nerva_numpy.matrix_operations
Matrix operations built on top of torch to support the math in the library.
The functions here intentionally mirror the names in the accompanying docs. They operate on 1D/2D tensors and keep broadcasting explicit for clarity.
Functions
|
Create diagonal matrix with x as diagonal. |
|
Element-wise absolute value |X|. |
|
Element-wise application of function f to X. |
|
Element-wise clip of X to [a_min, a_max]. |
|
Repeat column vector x horizontally n times. |
|
Returns a column vector with the maximum values of each row in X. |
|
Returns a column vector with the mean values of each row in X. |
|
Sum over columns (returns row vector). |
|
Extract diagonal of X as a vector. |
|
Dot product of vectors x and y. |
|
Returns the sum of the elements of X. |
|
Element-wise exponential exp(X). |
|
Element-wise product X ⊙ Y. |
|
Returns the nxn identity matrix. |
|
Element-wise inverse square root X^(-1/2) with epsilon for stability. |
Check if x can be treated as a column vector. |
|
Check if x can be treated as a row vector. |
|
|
Check if X is a square matrix. |
|
Check if x is a 1D tensor. |
|
Element-wise natural logarithm log(X). |
|
Element-wise log(sigmoid(X)) computed stably. |
|
Returns an mxn matrix with all elements equal to 1. |
|
Matrix multiplication X @ Y. |
|
Element-wise reciprocal 1/X. |
|
Repeat row vector x vertically m times. |
|
Returns a row vector with the maximum values of each column in X. |
|
Returns a row vector with the mean values of each column in X. |
|
Sum over rows (returns column vector). |
|
Element-wise square root √X. |
|
Element-wise square X². |
|
Get size along first dimension. |
|
Returns an mxn matrix with all elements equal to 0. |
- nerva_numpy.matrix_operations.is_column_vector(x: numpy.ndarray) bool[source]
Check if x can be treated as a column vector.
- nerva_numpy.matrix_operations.is_row_vector(x: numpy.ndarray) bool[source]
Check if x can be treated as a row vector.
- nerva_numpy.matrix_operations.vector_size(x: numpy.ndarray) int[source]
Get size along first dimension.
- nerva_numpy.matrix_operations.is_square(X: numpy.ndarray) bool[source]
Check if X is a square matrix.
- nerva_numpy.matrix_operations.dot(x: numpy.ndarray, y: numpy.ndarray)[source]
Dot product of vectors x and y.
- nerva_numpy.matrix_operations.zeros(m: int, n=None) numpy.ndarray[source]
Returns an mxn matrix with all elements equal to 0.
- nerva_numpy.matrix_operations.ones(m: int, n=None) numpy.ndarray[source]
Returns an mxn matrix with all elements equal to 1.
- nerva_numpy.matrix_operations.identity(n: int) numpy.ndarray[source]
Returns the nxn identity matrix.
- nerva_numpy.matrix_operations.product(X: numpy.ndarray, Y: numpy.ndarray) numpy.ndarray[source]
Matrix multiplication X @ Y.
- nerva_numpy.matrix_operations.hadamard(X: numpy.ndarray, Y: numpy.ndarray) numpy.ndarray[source]
Element-wise product X ⊙ Y.
- nerva_numpy.matrix_operations.diag(X: numpy.ndarray) numpy.ndarray[source]
Extract diagonal of X as a vector.
- nerva_numpy.matrix_operations.Diag(x: numpy.ndarray) numpy.ndarray[source]
Create diagonal matrix with x as diagonal.
- nerva_numpy.matrix_operations.elements_sum(X: numpy.ndarray)[source]
Returns the sum of the elements of X.
- nerva_numpy.matrix_operations.column_repeat(x: numpy.ndarray, n: int) numpy.ndarray[source]
Repeat column vector x horizontally n times.
- nerva_numpy.matrix_operations.row_repeat(x: numpy.ndarray, m: int) numpy.ndarray[source]
Repeat row vector x vertically m times.
- nerva_numpy.matrix_operations.columns_sum(X: numpy.ndarray) numpy.ndarray[source]
Sum over columns (returns row vector).
- nerva_numpy.matrix_operations.rows_sum(X: numpy.ndarray) numpy.ndarray[source]
Sum over rows (returns column vector).
- nerva_numpy.matrix_operations.columns_max(X: numpy.ndarray) numpy.ndarray[source]
Returns a column vector with the maximum values of each row in X.
- nerva_numpy.matrix_operations.rows_max(X: numpy.ndarray) numpy.ndarray[source]
Returns a row vector with the maximum values of each column in X.
- nerva_numpy.matrix_operations.columns_mean(X: numpy.ndarray) numpy.ndarray[source]
Returns a column vector with the mean values of each row in X.
- nerva_numpy.matrix_operations.rows_mean(X: numpy.ndarray) numpy.ndarray[source]
Returns a row vector with the mean values of each column in X.
- nerva_numpy.matrix_operations.apply(f, X: numpy.ndarray) numpy.ndarray[source]
Element-wise application of function f to X.
- nerva_numpy.matrix_operations.exp(X: numpy.ndarray) numpy.ndarray[source]
Element-wise exponential exp(X).
- nerva_numpy.matrix_operations.log(X: numpy.ndarray) numpy.ndarray[source]
Element-wise natural logarithm log(X).
- nerva_numpy.matrix_operations.reciprocal(X: numpy.ndarray) numpy.ndarray[source]
Element-wise reciprocal 1/X.
- nerva_numpy.matrix_operations.square(X: numpy.ndarray) numpy.ndarray[source]
Element-wise square X².
- nerva_numpy.matrix_operations.sqrt(X: numpy.ndarray) numpy.ndarray[source]
Element-wise square root √X.
- nerva_numpy.matrix_operations.inv_sqrt(X: numpy.ndarray) numpy.ndarray[source]
Element-wise inverse square root X^(-1/2) with epsilon for stability.
- nerva_numpy.matrix_operations.log_sigmoid(X: numpy.ndarray) numpy.ndarray[source]
Element-wise log(sigmoid(X)) computed stably.