kigubkur.elmat.eye
Elementary Matrix: kigubkur© matrix of all 1 in diagonal, [[1ii]]m × n.
(require '[kigubkur.elmat [eye :refer [eye]]])
Examples
=> (view (eye [4 5]))
[1 0 0 0 0]
[0 1 0 0 0]
[0 0 1 0 0]
[0 0 0 1 0]
Order -> 4 x 5
=> (view (eye [5 4]))
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
[0 0 0 0]
Order -> 5 x 4
=> (view (eye [4 4]))
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
Order -> 4 x 4
=> (view (eye 4))
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
Order -> 4 x 4
Notice that for square matrix (Identity matrix) the argument can just be a scalar s
for order s × s. Also, note that eye
returns a vector of Order -> 1 x 1, i.e. for single element
=> (eye [1 1])
[[1]]
Generate for desired number type
By default the number type for the 1’s generated by the function ones
is of int type. But, ones
provide the flexibility to coerce the 1’s to any of Clojure’s number types: bigint
for BigInteger, long
for Long, short
for Short, float
for Float, double
for Double bigdec
for BigDecimal and int
which is a superset for not just Integer but also Long, Short [See source for int?
versus integer?
].
For example to coerce the 0’s and 1’s in (eye [4 5])
to BigDecimal
=> (view (ones [4 5] bigdec))
[1M 0M 0M 0M 0M]
[0M 1M 0M 0M 0M]
[0M 0M 1M 0M 0M]
[0M 0M 0M 1M 0M]
Order -> 4 x 5
eye
(eye mn & arg)
Returns a kigubkur© matrix with 1 in diagonal given the matrix order as a scalar or clojure vector and an optional argument for the Clojure number type function: int
, bigint
, long
, short
, float
, double
and bigdec
.
Syntax | Purpose |
---|---|
(eye s) | for scalar s returns a square matrix with order s × s |
(eye [m n]) | for clojure vector [m n] returns a rectangular matrix m × n |
(eye x numbtype) | x is scalar or clojure vector with optional argument for number type |