numpy.ix_() function | Python

numpy.ix_() function 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.

Syntax : numpy.ix_(args)
Parameters :
args : [1-D sequences] Each sequence should be of integer or boolean type.
Return : [tuple of ndarrays] N arrays with N dimensions each, with N the number of input sequences. Together these arrays form an open mesh.

Code #1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program explaining
# numpy.ix_() function
  
# importing numpy as geek 
import numpy as geek
  
gfg = geek.ix_([0, 1], [2, 4])
  
print (gfg)

chevron_right


Output :

(array([[0],
       [1]]), array([[2, 4]]))

 
Code #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program explaining
# numpy.ix_() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.arange(10).reshape(2, 5)
print("Initial array : \n", arr) 
  
ixgrid = geek.ix_([0, 1], [2, 4])
  
print("New array : \n", arr[ixgrid]) 

chevron_right


Output :

Initial array : 
 [[0 1 2 3 4]
 [5 6 7 8 9]]
New array : 
 [[2 4]
 [7 9]]
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.