Element-wise operations
Every element-wise operator comes in two forms:
- Instance (in-place):
m.add(value)mutatesmand returnsthis. - Static (new matrix):
Matrix.add(m, value)returns a new matrix.
value may be a scalar (number) or another matrix / 2D array of the same
shape. With a matrix operand, shapes must match (else RangeError).
Arithmetic
add, sub (alias subtract), mul (alias multiply), div (alias
divide), mod (alias modulus), pow.
pow accepts a scalar or a same-shape matrix (element-wise exponent). For the
matrix power Aⁿ use mpow (see linear-algebra).
Bitwise
and, or, xor, leftShift, signPropagatingRightShift, rightShift
(alias zeroFillRightShift), not.
Math functions (unary)
Apply the corresponding Math.* function to every element: