def get_index_first_non_zero_slice(self, dimension):
"""Get the index of the first non zero slice in this map.
Args:
dimension (int): the dimension to search in
Returns:
int: the slice index with the first non zero values.
"""
slice_index = [slice(None)] * (self.max_dimension() + 1)
if dimension > len(slice_index) - 1:
raise ValueError('The given dimension {} is not supported.'.format(dimension))
for index in range(self.shape[dimension]):
slice_index[dimension] = index
if np.count_nonzero(self.data[slice_index]) > 0:
return index
return 0
评论列表
文章目录