intro to ann 

Run Settings
LanguageRust
Language Version
Run Command
use ndarray::{arr2, Array1}; #[derive(Default)] struct Neuron { w: Array1<f32>, b: f32, } impl Neuron { // fn new_weight(old_weight:Array1<f32>) -> Array1<f32> { // } fn activate(&self, x:Array1<f32>) -> i8 { let y:i8 = if self.w.dot(&x) + self.b > 0.0 { 1 } else { -1 }; println!("(w:{} * x:{}) + b:{} = y:{}", self.w, x, self.b, y); return y; } } fn main() { let n: Neuron = Default::default(); let x = arr2(&[[-1.0, 1.0], [0.0, -1.0], [10.0, 1.0],]); n.activate(x[0]); // n.activate(x[1]); // n.activate(x[2]); } __END__ error[E0277]: the trait bound `{integer}: NdIndex<Dim<[usize; 2]>>` is not satisfied --> src/main.rs:28:16 | 28 | n.activate(x[0]); | ^^^^ the trait `NdIndex<Dim<[usize; 2]>>` is not implemented for `{integer}` | = help: the following implementations were found: <&'a Dim<IxDynImpl> as NdIndex<Dim<IxDynImpl>>> <&'a [usize] as NdIndex<Dim<IxDynImpl>>> <() as NdIndex<Dim<[usize; 0]>>> <(usize, usize) as NdIndex<Dim<[usize; 2]>>> and 27 others = note: required because of the requirements on the impl of `std::ops::Index<{integer}>` for `ArrayBase<OwnedRepr<{float}>, Dim<[usize; 2]>>` error[E0308]: mismatched types --> src/main.rs:28:16 | 28 | n.activate(x[0]); | ^^^^ expected struct `ArrayBase`, found floating-point number | = note: expected struct `ArrayBase<OwnedRepr<f32>, Dim<[usize; 1]>>` found type `{float}`
Editor Settings
Theme
Key bindings
Full width
Lines