赞
踩
方法1使用np.meshgrid,然后堆叠-
r,c = np.meshgrid(*m)
out = np.column_stack((r.ravel('F'), c.ravel('F') ))
方法2或者,使用np.array()然后进行转置,重塑-
np.array(np.meshgrid(*m)).T.reshape(-1,len(m))
对于np.ix_中使用的通用数组数目的通用情况,这里是需要进行的修改-
p = np.r_[2:0:-1,3:len(m)+1,0]
out = np.array(np.meshgrid(*m)).transpose(p).reshape(-1,len(m))
样品运行-
两个数组的情况:
In [376]: m = np.ix_([0, 2, 4], [1, 3])
In [377]: p = np.r_[2:0:-1,3:len(m)+1,0]
In [378]: np.array(np.meshgrid(*m)).transpose(p).reshape(-1,len(m))
Out[378]:
array([[0, 1],
[0, 3],
[2, 1],
[2, 3],
[4, 1],
[4, 3]])
三个数组的情况:
In [379]: m = np.ix_([0, 2, 4], [1, 3],[6,5,9])
In [380]: p = np.r_[2:0:-1,3:len(m)+1,0]
In [381]: np.array(np.meshgrid(*m)).transpose(p).re
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。