Indexing routines#

Generating index arrays#

c_

r_

nonzero(a)

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.

mask_indices(n, mask_func[, k])

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

tril_indices(n[, k, m])

Returns the indices of the lower triangular matrix.

tril_indices_from(arr[, k])

Returns the indices for the lower-triangle of arr.

triu_indices(n[, k, m])

Returns the indices of the upper triangular matrix.

triu_indices_from(arr[, k])

Returns indices for the upper-triangle of arr.

ix_(*args)

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.

diag_indices_from(arr)

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.

put_along_axis(arr, indices, values, axis)

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

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#

flatiter(a)

Flat iterator object to iterate over arrays.