bundles / scipy 1.17.1 / scipy / ndimage / _measurements / sum_labels
function
scipy.ndimage._measurements:sum_labels
Signature
def sum_labels ( input , labels = None , index = None ) Summary
Calculate the sum of the values of the array.
Parameters
input: array_likeValues of
inputinside the regions defined bylabelsare summed together.labels: array_like of ints, optionalAssign labels to the values of the array. Has to have the same shape as
input.index: array_like, optionalA single label number or a sequence of label numbers of the objects to be measured.
Returns
sum: ndarray or scalarAn array of the sums of values of
inputinside the regions defined bylabelswith the same shape asindex. If 'index' is None or scalar, a scalar is returned.
Notes
Array API Standard Support
sum_labels has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy import ndimage input = [0,1,2,3] labels = [1,1,2,2]✓
ndimage.sum_labels(input, labels, index=[1,2]) ndimage.sum_labels(input, labels, index=1) ndimage.sum_labels(input, labels)✗
See also
- mean
- median
Aliases
-
scipy.ndimage.sum_labels