Handbook
Glossary
<eye> ( m n k z -- matrix )
Matrix operations
Prev:
<simple-eye> ( m n k -- matrix )
Next:
<coordinate-matrix> ( dim -- coordinates )
Vocabulary
math
.
matrices
Inputs
m
an
integer
n
an
integer
k
an
integer
z
an
object
Outputs
matrix
a
matrix
Word description
Creates an
m x n
matrix with a diagonal of
z
offset by
k
from the main diagonal. A positive value of
k
gives a diagonal above the main diagonal, whereas a negative value of
k
gives a diagonal below the main diagonal.
Examples
USING: math.matrices prettyprint ; 5 6 0 4 <eye> .
{ { 4 0 0 0 0 0 } { 0 4 0 0 0 0 } { 0 0 4 0 0 0 } { 0 0 0 4 0 0 } { 0 0 0 0 4 0 } }
USING: math.matrices prettyprint ; 5 5 2 2 <eye> .
{ { 0 0 2 0 0 } { 0 0 0 2 0 } { 0 0 0 0 2 } { 0 0 0 0 0 } { 0 0 0 0 0 } }
Definition
USING:
kernel
math
sequences
;
IN:
math.matrices
:
<eye>
( m n k z -- matrix )
[
[
<iota>
]
bi@
]
2dip
[
[
neg
+
=
]
curry
]
dip
[
0
?
]
curry
compose
cartesian-map
;
inline