{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / util / _map_array / ArrayMap

class

skimage.util._map_array:ArrayMap

source: /dev/scikit-image/src/skimage/util/_map_array.py :76

Signature

class   ArrayMap ( in_values out_values )

Members

Summary

Class designed to mimic mapping by NumPy array indexing.

Extended Summary

This class is designed to replicate the use of NumPy arrays for mapping values with indexing:

>>> values = np.array([0.25, 0.5, 1.0])
>>> indices = np.array([[0, 0, 1], [2, 2, 1]])
>>> values[indices]
array([[0.25, 0.25, 0.5 ],
       [1.  , 1.  , 0.5 ]])

The issue with this indexing is that you need a very large values array if the values in the indices array are large.

>>> values = np.array([0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0])
>>> indices = np.array([[0, 0, 10], [0, 10, 10]])
>>> values[indices]
array([[0.25, 0.25, 1.  ],
       [0.25, 1.  , 1.  ]])

Using this class, the approach is similar, but there is no need to create a large values array:

>>> in_indices = np.array([0, 10])
>>> out_values = np.array([0.25, 1.0])
>>> values = ArrayMap(in_indices, out_values)
>>> values
ArrayMap(array([ 0, 10]), array([0.25, 1.  ]))
>>> print(values)
ArrayMap:
  00.25
  101.0
>>> indices = np.array([[0, 0, 10], [0, 10, 10]])
>>> values[indices]
array([[0.25, 0.25, 1.  ],
       [0.25, 1.  , 1.  ]])

Parameters

in_values : array of int, shape (K,)

The source values from which to map.

out_values : array, shape (K,)

The destination values from which to map.

Aliases

  • skimage.util._map_array.ArrayMap