column-map ( matrix quot: ( ... col -- ... col' ) -- matrix' ) (original) (raw)

column-map ( matrix quot: ( ... col -- ... col' ) -- matrix' )
Matrix operations

Prev: matrix-map ( matrix quot: ( ... elt -- ... elt' ) -- matrix' )
Next: stitch ( m -- m' )

Vocabulary
math.matrices

Inputs

matrix a matrix
quot a quotation with stack effect ( ... col -- ... col' )

Outputs

matrix' a sequence, a matrix, or f

Word description
Apply the quotation to every column of the matrix. The output of the quotation must be a sequence.

Notes

This word is intended for use with "flat" (2-dimensional) matrices.
This word is the transpose variant of map.

Examples

USING: sequences math.matrices prettyprint ; 3 [ reverse ] column-map .
{ { 0 0 1 } { 0 1 0 } { 1 0 0 } }

Definition

USING: kernel sequences ;

IN: math.matrices

: column-map
( matrix quot: ( ... col -- ... col' ) -- matrix' )
[ transpose ] dip map transpose ; inline