将列表组合成网格参数

All*_*len 3 numpy python-3.x pandas

我正在使用这个函数,它可以很好地为我提供所有可能的数组组合的 numpy 数组

 arrs = np.array(np.meshgrid([1,2,3], [4,5,6], [7,8,9])).T.reshape(-1,3)
Run Code Online (Sandbox Code Playgroud)

但我想做的是获取 3 个列表并创建网格参数,如下所示:

lst1=[1,2,3]
lst2=[4,5,6]
lst3=[7,8,9]

arrs = np.array(np.meshgrid(lst)).T.reshape(-1,3)
Run Code Online (Sandbox Code Playgroud)

但是我如何从 3 个列表中创建 lst 呢?如果我这样做

lst=[lst1,lst2,lst3]
Run Code Online (Sandbox Code Playgroud)

我得到的只是一个错误。谢谢。

Qua*_*ang 5

您需要解压lst

# notice the *
arrs = np.array(np.meshgrid(*lst)).T.reshape(-1,3)
Run Code Online (Sandbox Code Playgroud)