h distinct value in the input array. >>> val_indices.keys() dict_keys([0, 1, 2, 3]) The entry for each value is an index tuple, locating the elements with that value. >>> ndx1 = val_indices[1] >>> ndx1 (array([2, 2, 3, 3, 4]), array([2, 3, 2, 3, 4])) This can be used to index into the original array, or any other array with the same shape. >>> a[ndx1] array([1, 1, 1, 1, 1]) If the zeros were to be ignored, then the resulting dictionary would no longer have an entry for zero. >>> val_indices = ndimage.value_indices(a, ignore_value=0) >>> val_indices.keys() dict_keys([1, 2, 3]) )