Indexing routines

See also

Indexing

Generating index arrays

methoddescription
c_open in new windowTranslates slice objects to concatenation along the second axis.
r_open in new windowTranslates slice objects to concatenation along the first axis.
s_open in new windowA nicer way to build up index tuples for arrays.
nonzeroopen in new window(a)Return the indicesopen in new window of the elements that are non-zero.
whereopen in new window(condition, [x, y])Return elements chosen from x or y depending on condition.
indices(dimensions[, dtype, sparse])Return an array representing the indices of a grid.
ix_open in new window(*args)Construct an open mesh from multiple sequences.
ogridopen in new windownd_grid instance which returns an open multi-dimensional “meshgrid”.
ravel_multi_indexopen in new window(multi_index, dims[, mode, …])Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.
unravel_indexopen in new window(indices, shape[, order])Converts a flat index or array of flat indices into a tuple of coordinate arrays.
diag_indicesopen in new window(n[, ndim])Return the indices to access the main diagonal of an array.
diag_indices_fromopen in new window(arr)Return the indices to access the main diagonal of an n-dimensional array.
mask_indicesopen in new window(n, mask_func[, k])Return the indices to access (n, n) arrays, given a masking function.
tril_indicesopen in new window(n[, k, m])Return the indices for the lower-triangle of an (n, m) array.
tril_indices_fromopen in new window(arr[, k])Return the indices for the lower-triangle of arr.
triu_indicesopen in new window(n[, k, m])Return the indices for the upper-triangle of an (n, m) array.
triu_indices_fromopen in new window(arr[, k])Return the indices for the upper-triangle of arr.

Indexing-like operations

methoddescription
takeopen in new window(a, indices[, axis, out, mode])Take elements from an array along an axis.
take_along_axisopen in new window(arr, indices, axis)Take values from the input array by matching 1d index and data slices.
chooseopen in new window(a, choices[, out, mode])Construct an array from an index array and a set of arrays to choose from.
compressopen in new window(condition, a[, axis, out])Return selectopen in new windowed slices of an array along given axis.
diagopen in new window(v[, k])Extract a diagonalopen in new window or construct a diagonal array.
diagonalopen in new window(a[, offset, axis1, axis2])Return specified diagonals.
selectopen in new window(condlist, choicelist[, default])Return an array drawn from elements in choicelist, depending on conditions.
lib.stride_tricks.as_stridedopen in new window(x[, shape, …])Create a view into the array with the given shape and strides.

Inserting data into arrays

methoddescription
placeopen in new window(arr, mask, vals)Change elements of an array based on conditional and inputopen in new window values.
putopen in new window(a, ind, v[, mode])Replaces specified elements of an array with given values.
put_along_axisopen in new window(arr, indices, values, axis)Put values into the destination array by matching 1d index and data slices.
putmaskopen in new window(a, mask, values)Changes elements of an array based on conditional and input values.
fill_diagonalopen in new window(a, val[, wrap])Fill the main diagonal of the given array of any dimensionality.

Iterating over arrays

methoddescription
nditeropen in new windowEfficient multi-dimensional iterator object to iterate over arrays.
ndenumerateopen in new window(arr)Multidimensional index iterator.
ndindexopen in new window(*shape)An N-dimensional iterator object to index arrays.
nested_itersopen in new window()Create nditers for use in nested loops
flatiteropen in new windowFlat iterator object to iterate over arrays.
lib.Arrayteratoropen in new window(var[, buf_size])Buffered iterator for big arrays.