Indexing routines#

Generating index arrays#

diag_indices(n[, ndim])

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

diag_indices_from(arr)

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

mask_indices(n, mask_func[, k])

Return the indices to access (n, n) arrays, given a masking function.

tril_indices(n[, k, m])

Return the indices for the lower-triangle of an (n, m) array.

tril_indices_from(arr[, k])

Return the indices for the lower-triangle of arr.

triu_indices(n[, k, m])

Return the indices for the upper-triangle of an (n, m) array.

triu_indices_from(arr[, k])

Return the indices for the upper-triangle of arr.

indices(dimensions[, dtype, sparse])

Return an array representing the indices of a grid.

nonzero(a)

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

where(condition, [x, y])

Return elements chosen from x or y depending on condition.

Indexing-like operations#

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

Construct an array from an index array and a list of arrays to choose from.

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

Return selected slices of an array along given axis.

diag(v[, k])

Extract a diagonal or construct a diagonal array.

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

Return specified diagonals.

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

Take elements from an array along an axis.

take_along_axis(a, indices, axis)

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

Inserting data into arrays#

put_along_axis(a, indices, values, axis)

Put values into the destination array by matching 1d index and data slices.