MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / main

Function main

19_numpy/rust/simple/src/main.rs:4–21  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2use std::f64::consts::PI;
3
4fn main() -> Result<(), ndarray::ShapeError> {
5 let a: Array1<f64> = array![0., 30., 45., 60., 90.];
6
7 println!("angles {}", a);
8 println!("sine(a) {}", (a * PI / 180_f64).map(|x| x.sin()));
9
10 let a = Array::from_shape_vec((3, 3), Array1::range(0., 9., 1.).to_vec())?;
11 let b = array![10., 10., 10.];
12
13 println!("a: {}", &a);
14 println!("b: {}", &b);
15 println!("a * 2 {}", &a * 2.);
16 println!("a + b {}", &a + &b); // & makes an ArrayView, avoiding move
17 println!("a * b {}", &a * &b);
18 println!("average(a) {}", a.sum() / a.len() as f64);
19 println!("mean(b) {}", b.mean().unwrap());
20 Ok(())
21}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected