File: column_standardize.rs

package info (click to toggle)
rust-ndarray 0.16.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,028 kB
  • sloc: sh: 30; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 805 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#[cfg(feature = "std")]
use ndarray::prelude::*;

#[cfg(feature = "std")]
fn main()
{
    // This example recreates the following from python/numpy
    // counts -= np.mean(counts, axis=0)
    // counts /= np.std(counts, axis=0)

    let mut data = array![[-1., -2., -3.], [1., -3., 5.], [2., 2., 2.]];

    println!("{:8.4}", data);
    println!("Mean along axis=0 (along columns):\n{:8.4}", data.mean_axis(Axis(0)).unwrap());

    data -= &data.mean_axis(Axis(0)).unwrap();
    println!("Centered around mean:\n{:8.4}", data);

    data /= &data.std_axis(Axis(0), 0.);
    println!("Scaled to normalize std:\n{:8.4}", data);

    println!("New mean:\n{:8.4}", data.mean_axis(Axis(0)).unwrap());
    println!("New std: \n{:8.4}", data.std_axis(Axis(0), 0.));
}

#[cfg(not(feature = "std"))]
fn main() {}