'Turn argmin, argmax output into an advanced index.
Argmin, argmax output contains indices along a given axis in an array
shaped like the other dimensions.  To use this to get values at the
correct location, a list is constructed in which the other axes are
indexed sequentially.  For ``keepdims`` is ``True``, the net result is
the same as constructing an index grid with ``np.ogrid`` and then
replacing the ``axis`` item with ``indices`` with its shaped expanded
at ``axis``. For ``keepdims`` is ``False``, the result is the same but
with the ``axis`` dimension removed from all list entries.
For ``axis`` is ``None``, this calls :func:`~numpy.unravel_index`.
Parameters
indices : array
Output of argmin or argmax.
axis : int or None
axis along which argmin or argmax was used.
keepdims : bool
Whether to construct indices that keep or remove the axis along
which argmin or argmax was used.  Default: ``False``.
Returns
advanced_index : list of arrays
Suitable for use as an advanced index.'

def _advanced_index(self, indices, axis=None, keepdims=False):

    if (axis is None):
        return np.unravel_index(indices, self.shape)
    ndim = self.ndim
    if (axis < 0):
        axis = (axis + ndim)
    if (keepdims and (indices.ndim < self.ndim)):
        indices = np.expand_dims(indices, axis)
    return [(indices if (i == axis) else np.arange(s).reshape(((((1,) * (i if (keepdims or (i < axis)) else (i - 1))) + (s,)) + ((1,) * ((ndim - i) - (1 if (keepdims or (i > axis)) else 2)))))) for (i, s) in enumerate(self.shape)]
