kigubkur.datafun.maximum
Maximum function
(require '[kigubkur.datafun [maximum :refer [maxval]]])
Examples
Maximum element in a vector
This returns the maximum element.
=> (def r [[1 2 3 4]])
=> (def c [[1][2][3][4]])
=> (view r)
[1 2 3 4]
Order -> 1 x 4
=> (maxval r)
4
=> (view c)
[1]
[2]
[3]
[4]
Order -> 4 x 1
=> (maxval c)
4
Maximum of a matrix
By default this returns a row vector containing the maximum element of each column.
=> (def M [[2 8 4] [7 3 9]])
=> (view M)
[2 8 4]
[7 3 9]
Order -> 2 x 3
=> (view (maxval M))
[7 8 9]
Order -> 1 x 3
But for maximum element of each row
=> (maxval M "rows")
[[8 9]]
Maximum of a block
(require '[kigubkur.construct [blocking :refer [block]]])
=> (def L [[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]])
=> (def B (block L 5))
=> (pprint B)
[[{:A11 [[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]],
:A12 [[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]
[6 7 8 9 10]]}]
[{:A22 [[6 7 8 9 10]
[6 7 8 9 10]],
:A21 [[1 2 3 4 5]
[1 2 3 4 5]]}]]
=> (maxval B)
[[1 2 3 4 5 6 7 8 9 10]]
=> (maxval B "rows")
[[10 10 10 10 10 10 10]]
maxval
(maxval M & arg)
Returns maximum of all column or row elements or maximum of each column or row vector elements in a matrix and returns a scalar or a row-vector.
Syntax | Purpose |
---|---|
(maxval x) | maximum element; x is a row/column |
(maxval x) | row containing maximum of each column; x is a matrix/block |
(maxval x "rows") | row containing maximum of each row; x is a matrix/block |