pub fn random_binary_matrix(
n_rows: usize,
n_cols: usize,
density: f64,
seed: Option<u64>,
) -> StatsResult<Array2<i32>>Expand description
Generate a random binary matrix with specified shape and density
§Arguments
n_rows- Number of rowsn_cols- Number of columnsdensity- Probability of non-zero elementsseed- Optional seed for reproducibility
§Returns
- Random binary matrix
§Examples
use scirs2_stats::random::random_binary_matrix;
// Generate a 5x5 binary matrix with 30% non-zero elements
let matrix = random_binary_matrix(5, 5, 0.3, Some(42)).expect("Operation failed");
// The matrix should have the correct shape
assert_eq!(matrix.shape(), &[5, 5]);
// All elements should be either 0 or 1
for &val in matrix.iter() {
assert!(val == 0 || val == 1);
}