#NEWLINE# def index_along_axis( index , ndim , axis ) : #NEWLINE# #INDENT# '\n    Create a slice tuple for indexing into a NumPy array along a\n    (single) given axis.\n\n    Parameters\n    ----------\n    index : array_like or slice\n        The value you wish to index with along `axis`.\n    ndim : int\n        The number of dimensions in the array into which you are indexing\n        (i.e. the value returned in the `.ndim` attribute).\n    axis : int\n        The axis along which you wish to index.\n\n    Returns\n    -------\n    indices : tuple\n        A slice tuple that can be used to index an array, selecting all\n        elements along every axis except `axis`, for which `index` is used\n        instead.\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> a = np.arange(27).reshape((3, 3, 3))\n    >>> index = index_along_axis([0, 2], 3, 2)\n    >>> np.all(a[index] == a[:, :, [0, 2]])\n    True\n    >>> index = index_along_axis([0, 2], 3, 1)\n    >>> np.all(a[index] == a[:, [0, 2]])\n    True\n    >>> index = index_along_axis([0, 2], 3, 0)\n    >>> np.all(a[index] == a[[0, 2]])\n    True\n    ' #NEWLINE# indices = ( [ slice ( None ) ] * indices ) #NEWLINE# indices [ axis ] = index #NEWLINE# return tuple ( indices )