[][src]Function mnist_read::read_labels

pub fn read_labels(path: &str) -> Vec<u8>

Reads MNIST format labels.

Returns Vec<usize> (length = number of labels).

let test_labels: Vec<u8> = mnist_read::read_labels("mnist/t10k-labels.idx1-ubyte");

assert_eq!(test_labels.len(),10000);

for label in test_labels {
    assert!(label <= 9)
}

For ndarray one might do:

let u8_labels:Vec<u8> = mnist_read::read_labels("mnist/t10k-labels.idx1-ubyte");
let usize_labels:Vec<usize> = u8_labels.into_iter().map(|l|l as usize).collect();
let array_labels:ndarray::Array2<usize> = ndarray::Array::from_shape_vec((10000, 1), usize_labels).expect("Bad labels");
assert_eq!(array_labels.shape(),&[10000,1]);