Numpy的meshgrid对于将两个向量转换为坐标网格非常有用.将此扩展到三维的最简单方法是什么?因此,给定三个向量x,y和z,构造可用作坐标的3x3D阵列(而不是2x2D阵列).
是否有类似于R中的expand.grid()函数的Python函数?提前致谢.
(编辑)以下是此R功能的说明和示例.
Create a Data Frame from All Combinations of Factors
Description:
Create a data frame from all combinations of the supplied vectors
or factors.
> x <- 1:3
> y <- 1:3
> expand.grid(x,y)
Var1 Var2
1 1 1
2 2 1
3 3 1
4 1 2
5 2 2
6 3 2
7 1 3
8 2 3
9 3 3
Run Code Online (Sandbox Code Playgroud)
(EDIT2)下面是rpy包的示例.我想得到相同的输出对象但不使用R:
>>> from rpy import *
>>> a = [1,2,3]
>>> b = [5,7,9]
>>> r.assign("a",a) …Run Code Online (Sandbox Code Playgroud)