numpy.ix_()函数| Python
numpy.ix_()
函数从多个序列构造一个开放网格。此函数采用 N 个一维序列并返回 N 个输出,每个输出具有 N 个维度,使得除了一维之外的所有形状都为 1,并且具有非单位形状值的维度在所有 N 维度中循环。
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.
代码#1:
# Python program explaining
# numpy.ix_() function
# importing numpy as geek
import numpy as geek
gfg = geek.ix_([0, 1], [2, 4])
print (gfg)
输出 :
(array([[0],
[1]]), array([[2, 4]]))
代码#2:
# 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])
输出 :
Initial array :
[[0 1 2 3 4]
[5 6 7 8 9]]
New array :
[[2 4]
[7 9]]