You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / ix_

_ArrayFunctionDispatcher

numpy:ix_

source: /numpy/lib/_index_tricks_impl.py :31

Signature

def   ix_ ( * args )

Summary

Construct an open mesh from multiple sequences.

Extended Summary

This function takes N 1-D sequences and returns N outputs with N dimensions each, such that the shape is 1 in all but one dimension and the dimension with the non-unit shape value cycles through all N dimensions.

Using ix_ one can quickly construct index arrays that will index the cross product. a[np.ix_([1,3],[2,5])] returns the array [[a[1,2] a[1,5]], [a[3,2] a[3,5]]].

Parameters

args : 1-D sequences

Each sequence should be of integer or boolean type. Boolean sequences will be interpreted as boolean masks for the corresponding dimension (equivalent to passing in np.nonzero(boolean_sequence)).

Returns

out : tuple of ndarrays

N arrays with N dimensions each, with N the number of input sequences. Together these arrays form an open mesh.

Examples

import numpy as np
a = np.arange(10).reshape(2, 5)
a
ixgrid = np.ix_([0, 1], [2, 4])
ixgrid
ixgrid[0].shape, ixgrid[1].shape
a[ixgrid]
ixgrid = np.ix_([True, True], [2, 4])
a[ixgrid]
ixgrid = np.ix_([True, True], [False, False, True, False, True])
a[ixgrid]

See also

meshgrid
mgrid
ogrid

Aliases

  • numpy.ix_