# [racket] Matrix Row/Col Ops

2013/5/7 Ray Racine <ray.racine at gmail.com>
>* First of all I've started using some of the new math and prob stuff "for
*>* real" and it's all fantastic work. Thank you.
*>*
*>* Was looking for a routine for sums of a matrix along the either the rows
*>* or cols axis.
*>*
*>* See http://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html
*>*
*>* I didn't notice anything but looks straightforward with
*>* matrix-map-rows/cols or similar.
*>*
*
I agree that we should some summing functions to the matrix library.
In the mean time, you can use the summing functions for arrays.
http://docs.racket-lang.org/math/array_fold.html?q=array&q=matrix-co&q=column&q=array&q=in-column#(form._((lib._math/array..rkt)._array-all-sum))
>* (require math)
*>* (define M (matrix [[1 2]
* [3 4]]))
>* (array-axis-sum M 0)
*(array #[4 6])
>* (array-axis-sum M 1)
*(array #[3 7])
>* (array-all-sum M)
*10
>* (array-all-sum (matrix-col M 0))
*4
This reminds me that we need to bring back in-column and
in-row so one can use them with for/sum and others.
https://code.google.com/p/racket/source/browse/collects/math/private/matrix/matrix-sequences.rkt?spec=svn9a48e5d1e5f65abc0d06ed5f98f8fcda0beae073&r=9a48e5d1e5f65abc0d06ed5f98f8fcda0beae073
If I recall correctly there were a problem to get in-row and in-sum to work
with both normal Racket and Typed Racket.
>* As I started one thing I noticed was the treatment of Matrix Rows and Cols
*>* as themselves a Matrix and not as a flat Array.
*>*
*>* > matrix-row
*>* - : (All (A) ((Array A) Integer -> (Array A)))
*>* #<procedure:matrix-row>
*>* > (matrix-row m 0)
*>* - : (Array Positive-Byte)
*>* (array #[#[1 2]])
*>*
*>* In lieu of (array #[#[1 2]]) I would have expected (array #[1 2]). In
*>* other words, a row or column of a matrix is a row or column vector.
*>*
*>* in fact currently
*>*
*>* > (matrix-row (matrix-row (matrix-row (matrix-row m 0) 0) 0) 0)
*>* - : (Array Positive-Byte)
*>* (array #[#[1 2]])
*>*
*>* What is the advantage of current approach?
*>*
*