ix_of_item_change_1d¶
-
mdtools.numpy_helper_functions.
ix_of_item_change_1d
(a)[source]¶ Get the indices of a 1-dimensional array where its elements change.
Deprecated since version 0.0.0.dev0:
ix_of_item_change_1d()
might be removed in future versions. It is replaced byix_of_item_change()
, since this function works for arrays with arbitrary dimensions and provides additional functionality.Todo
Check for scripts using this function before removing it.
- Parameters
a (array_like) – 1-dimensional array for which to get each index where its elements change.
- Returns
ix – The indices where the elements of a change. The first element of ix is always zero.
- Return type
See also
ix_of_item_change()
Same function for arrays of arbitrary dimension
Examples
>>> a = np.arange(3) >>> a array([0, 1, 2]) >>> mdt.nph.ix_of_item_change_1d(a) array([0, 1, 2])
>>> b = np.array([1, 2, 2, 3, 3, 3, 1]) >>> mdt.nph.ix_of_item_change_1d(b) array([0, 1, 3, 6])
>>> c = np.ones(3) >>> mdt.nph.ix_of_item_change_1d(c) array([0])
Edge cases:
>>> x = np.array([1]) >>> mdt.nph.ix_of_item_change_1d(x) array([0])
>>> x = np.array([]) >>> ix = mdt.nph.ix_of_item_change_1d(x) >>> ix array([0]) >>> x[ix] Traceback (most recent call last): ... IndexError: index 0 is out of bounds for axis 0 with size 0