Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/linalg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,10 @@ pub trait BaseMatrix<T: RealNumber>: Clone + Debug {

result
}
/// Take an individual column from the matrix.
fn take_column(&self, column_index: usize) -> Self {
self.take(&[column_index], 1)
}
}

/// Generic matrix with additional mixins like various factorization methods.
Expand Down Expand Up @@ -761,4 +765,21 @@ mod tests {
assert_eq!(m.take(&vec!(1, 1, 3), 0), expected_0);
assert_eq!(m.take(&vec!(1, 0), 1), expected_1);
}

#[test]
fn take_second_column_from_matrix() {
let four_columns: DenseMatrix<f64> = DenseMatrix::from_2d_array(&[
&[0.0, 1.0, 2.0, 3.0],
&[0.0, 1.0, 2.0, 3.0],
&[0.0, 1.0, 2.0, 3.0],
&[0.0, 1.0, 2.0, 3.0],
]);

let second_column = four_columns.take_column(1);
assert_eq!(
second_column,
DenseMatrix::from_2d_array(&[&[1.0], &[1.0], &[1.0], &[1.0]]),
"The second column was not extracted correctly"
);
}
}
4 changes: 3 additions & 1 deletion src/preprocessing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// Transform a data matrix by replaceing all categorical variables with their one-hot vector equivalents
/// Transform a data matrix by replacing all categorical variables with their one-hot vector equivalents
pub mod categorical;
mod data_traits;
/// Preprocess numerical matrices.
pub mod numerical;
/// Encode a series (column, array) of categorical variables as one-hot vectors
pub mod series_encoder;
Loading