pub trait MatrixPreprocessing<T: RealNumber>: MutArrayView2<T> + Clone {
// Provided methods
fn binarize_mut(&mut self, threshold: T) { ... }
fn binarize(self, threshold: T) -> Self
where Self: Sized { ... }
}
Expand description
Defines baseline implementations for various matrix processing functions
Provided Methods§
sourcefn binarize_mut(&mut self, threshold: T)
fn binarize_mut(&mut self, threshold: T)
Each element of the matrix greater than the threshold becomes 1, while values less than or equal to the threshold become 0
use smartcore::linalg::basic::matrix::DenseMatrix;
use smartcore::linalg::traits::stats::MatrixPreprocessing;
let mut a = DenseMatrix::from_2d_array(&[&[0., 2., 3.], &[-5., -6., -7.]]);
let expected = DenseMatrix::from_2d_array(&[&[0., 1., 1.],&[0., 0., 0.]]);
a.binarize_mut(0.);
assert_eq!(a, expected);
sourcefn binarize(self, threshold: T) -> Selfwhere
Self: Sized,
fn binarize(self, threshold: T) -> Selfwhere Self: Sized,
Returns new matrix where elements are binarized according to a given threshold.
use smartcore::linalg::basic::matrix::DenseMatrix;
use smartcore::linalg::traits::stats::MatrixPreprocessing;
let a = DenseMatrix::from_2d_array(&[&[0., 2., 3.], &[-5., -6., -7.]]);
let expected = DenseMatrix::from_2d_array(&[&[0., 1., 1.],&[0., 0., 0.]]);
assert_eq!(a.binarize(0.), expected);