cupyx.scipy.ndimage.labeled_comprehension(input, labels, index, func, out_dtype, default, pass_positions=False)[source]#

Array resulting from applying func to each labeled region.

Roughly equivalent to [func(input[labels == i]) for i in index].

Sequentially applies an arbitrary function (that works on array_like input) to subsets of an N-D image array specified by labels and index. The option exists to provide the function with positional parameters as the second argument.

  • input (cupy.ndarray) – Data from which to select labels to process.

  • labels (cupy.ndarray or None) – Labels to objects in input. If not None, array must be same shape as input. If None, func is applied to raveled input.

  • index (int, sequence of ints or None) – Subset of labels to which to apply func. If a scalar, a single value is returned. If None, func is applied to all non-zero values of labels.

  • func (callable) – Python function to apply to labels from input.

  • out_dtype (dtype) – Dtype to use for result.

  • default (int, float or None) – Default return value when a element of index does not exist in labels.

  • pass_positions (bool, optional) – If True, pass linear indices to func as a second argument.


Result of applying func to each of labels to input in index.

Return type: