@@ -2627,26 +2627,52 @@ impl FPMatrix for Matrix {
26272627 matrix ( result, self . row , self . col , self . shape )
26282628 }
26292629
2630+ /// Column map
2631+ ///
2632+ /// # Example
2633+ /// ```rust
2634+ /// use peroxide::fuga::*;
2635+ ///
2636+ /// fn main() {
2637+ /// let x = ml_matrix("1 2;3 4;5 6");
2638+ /// let y = x.col_map(|c| c.fmap(|t| t - c.mean()));
2639+ ///
2640+ /// assert_eq!(y, ml_matrix("-2 -2;0 0;2 2"));
2641+ /// }
2642+ /// ```
26302643 fn col_map < F > ( & self , f : F ) -> Matrix
26312644 where
26322645 F : Fn ( Vec < f64 > ) -> Vec < f64 > ,
26332646 {
26342647 let mut result = matrix ( vec ! [ 0f64 ; self . row * self . col] , self . row , self . col , Col ) ;
26352648
2636- for i in 0 ..self . row {
2649+ for i in 0 ..self . col {
26372650 result. subs_col ( i, & f ( self . col ( i) ) ) ;
26382651 }
26392652
26402653 result
26412654 }
26422655
2656+ /// Row map
2657+ ///
2658+ /// # Example
2659+ /// ```rust
2660+ /// use peroxide::fuga::*;
2661+ ///
2662+ /// fn main() {
2663+ /// let x = ml_matrix("1 2 3;4 5 6");
2664+ /// let y = x.row_map(|r| r.fmap(|t| t - r.mean()));
2665+ ///
2666+ /// assert_eq!(y, ml_matrix("-1 0 1;-1 0 1"));
2667+ /// }
2668+ /// ```
26432669 fn row_map < F > ( & self , f : F ) -> Matrix
26442670 where
26452671 F : Fn ( Vec < f64 > ) -> Vec < f64 > ,
26462672 {
26472673 let mut result = matrix ( vec ! [ 0f64 ; self . row * self . col] , self . row , self . col , Row ) ;
26482674
2649- for i in 0 ..self . col {
2675+ for i in 0 ..self . row {
26502676 result. subs_row ( i, & f ( self . row ( i) ) ) ;
26512677 }
26522678
0 commit comments