MCPcopy Create free account
hub / github.com/numpy/numpy / ix_

Function ix_

numpy/lib/index_tricks.py:35–106  ·  view source on GitHub ↗

Construct an open mesh from multiple sequences. 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_`

(*args)

Source from the content-addressed store, hash-verified

33
34@array_function_dispatch(_ix__dispatcher)
35def ix_(*args):
36 """
37 Construct an open mesh from multiple sequences.
38
39 This function takes N 1-D sequences and returns N outputs with N
40 dimensions each, such that the shape is 1 in all but one dimension
41 and the dimension with the non-unit shape value cycles through all
42 N dimensions.
43
44 Using `ix_` one can quickly construct index arrays that will index
45 the cross product. ``a[np.ix_([1,3],[2,5])]`` returns the array
46 ``[[a[1,2] a[1,5]], [a[3,2] a[3,5]]]``.
47
48 Parameters
49 ----------
50 args : 1-D sequences
51 Each sequence should be of integer or boolean type.
52 Boolean sequences will be interpreted as boolean masks for the
53 corresponding dimension (equivalent to passing in
54 ``np.nonzero(boolean_sequence)``).
55
56 Returns
57 -------
58 out : tuple of ndarrays
59 N arrays with N dimensions each, with N the number of input
60 sequences. Together these arrays form an open mesh.
61
62 See Also
63 --------
64 ogrid, mgrid, meshgrid
65
66 Examples
67 --------
68 >>> a = np.arange(10).reshape(2, 5)
69 >>> a
70 array([[0, 1, 2, 3, 4],
71 [5, 6, 7, 8, 9]])
72 >>> ixgrid = np.ix_([0, 1], [2, 4])
73 >>> ixgrid
74 (array([[0],
75 [1]]), array([[2, 4]]))
76 >>> ixgrid[0].shape, ixgrid[1].shape
77 ((2, 1), (1, 2))
78 >>> a[ixgrid]
79 array([[2, 4],
80 [7, 9]])
81
82 >>> ixgrid = np.ix_([True, True], [2, 4])
83 >>> a[ixgrid]
84 array([[2, 4],
85 [7, 9]])
86 >>> ixgrid = np.ix_([True, True], [False, False, True, False, True])
87 >>> a[ixgrid]
88 array([[2, 4],
89 [7, 9]])
90
91 """
92 out = []

Callers 1

test_repeated_inputMethod · 0.90

Calls 4

issubdtypeFunction · 0.90
astypeMethod · 0.80
nonzeroMethod · 0.80
reshapeMethod · 0.80

Tested by 1

test_repeated_inputMethod · 0.72