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: mdtools.numpy_helper_functions.ix_of_item_change_1d() might be removed in a future release. It is replaced by mdtools.numpy_helper_functions.ix_of_item_change(), because this function works for arrays with arbitrary dimensions and provides additional functionality. mdtools.numpy_helper_functions.ix_of_item_change() with prepend_zero set to True is equivalent to mdtools.numpy_helper_functions.ix_of_item_change_1d().

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 (numpy.ndarray) – The indices where the elements of a change. The first element of ix is always zero.

See also

mdtools.numpy_helper_functions.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