Indexing routines

Generating index arrays




Return the indices of the elements that are non-zero.

where(condition[, x, y])

Return elements, either from x or y, depending on condition.

indices(dimensions[, dtype])

Returns an array representing the indices of a grid.


Construct an open mesh from multiple sequences.

ravel_multi_index(multi_index, dims[, mode, …])

Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.

unravel_index(indices, dims[, order])

Converts array of flat indices into a tuple of coordinate arrays.

diag_indices(n[, ndim])

Return the indices to access the main diagonal of an array.


Return the indices to access the main diagonal of an n-dimensional array.

Indexing-like operations

take(a, indices[, axis, out])

Takes elements of an array at specified indices along an axis.

take_along_axis(a, indices, axis)

Take values from the input array by matching 1d index and data slices.

choose(a, choices[, out, mode])

compress(condition, a[, axis, out])

Returns selected slices of an array along given axis.

diag(v[, k])

Returns a diagonal or a diagonal array.

diagonal(a[, offset, axis1, axis2])

Returns specified diagonals.

select(condlist, choicelist[, default])

Return an array drawn from elements in choicelist, depending on conditions.

lib.stride_tricks.as_strided(x[, shape, strides])

Create a view into the array with the given shape and strides.

Inserting data into arrays

place(arr, mask, vals)

Change elements of an array based on conditional and input values.

put(a, ind, v[, mode])

Replaces specified elements of an array with given values.

putmask(a, mask, values)

Changes elements of an array inplace, based on a conditional mask and input values.

fill_diagonal(a, val[, wrap])

Fills the main diagonal of the given array of any dimensionality.

Iterating over arrays


Flat iterator object to iterate over arrays.