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.

flatnonzero(a)

Return indices that are non-zero in the flattened version of a.

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.

select(condlist, choicelist[, default])

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

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#

fill_diagonal(a, val[, wrap])

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

put(a, indices, values[, mode])

Replaces specified elements of an array with given values.

putmask(a, mask, values)

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

put_along_axis(a, indices, values, axis)

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

place(arr, mask, vals)

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