matrix-normalize ( m -- m' ) (original) (raw)
matrix-normalize ( m -- m' )
Matrix operations
Prev: | ( n -- matrix ) |
---|---|
Next: | mneg ( m -- m' ) |
Inputs
m | a matrix with at least 1 non-zero number |
---|
Outputs
m' | a matrix |
---|
Word description
Normalize a matrix containing at least 1 non-zero element. Each element from the input matrix is computed as a fraction of the maximum element. The maximum element becomes 1/1.
Notes
• | This word is intended for use with "flat" (2-dimensional) matrices. |
---|---|
• | This word assumes that elements of the input matrix are compatible with the following words:![]() ![]() ![]() |
Examples
USING: math.matrices prettyprint ; { { 5 9 } { 15 17 } } matrix-normalize .
{ { 5/17 9/17 } { 15/17 1 } }
Definition
: matrix-normalize ( m -- m' )
dup zero-matrix? [ dup mabs mmax m/n ] unless ; inline
foldable flushable