MCPcopy Create free account
hub / github.com/daniel-e/rustml / matrix_to_csv

Function matrix_to_csv

src/csv.rs:51–56  ·  view source on GitHub ↗

Converts a matrix into a comma seperated list of values. As delimiter between the columns the string `sep` is used. As delimiter between the rows a newline is used. # Example ``` # #[macro_use] extern crate rustml; use rustml::*; use rustml::csv::matrix_to_csv; # fn main() { let m = mat![1.0, 2.0; 3.0, 4.0]; assert_eq!(matrix_to_csv(&m, ","), "1,2\n3,4\n") # } ```

(m: &Matrix<T>, sep: &str)

Source from the content-addressed store, hash-verified

49/// # }
50/// ```
51pub fn matrix_to_csv<T: fmt::Display + Clone>(m: &Matrix<T>, sep: &str) -> String {
52
53 m.row_iter()
54 .map(|row| vec_to_csv(row, sep))
55 .fold(String::new(), |s, val| s + &val + "\n")
56}
57
58
59/// Reads a matrix from a CSV.

Callers

nothing calls this directly

Calls 3

vec_to_csvFunction · 0.85
mapMethod · 0.80
row_iterMethod · 0.80

Tested by

no test coverage detected