numpy.meshgrid modeled after the Matlab meshgrid . It is used to vectorize the functions of two variables, so you can write
x = numpy.array([1, 2, 3]) y = numpy.array([10, 20, 30]) XX, YY = numpy.meshgrid(x, y) ZZ = XX + YY ZZ => array([[11, 12, 13], [21, 22, 23], [31, 32, 33]])
So ZZ contains all combinations of x and y placed in the function. When you think about it, meshgrid little redundant for numpy arrays when they are being translated. That means you can do
XX, YY = numpy.atleast_2d(x, y) YY = YY.T
and get the same result.
mgrid and ogrid are helper classes that use index notation so you can directly create XX and YY in the previous examples without using something like linspace . The order in which the output is generated is reversed.
YY, XX = numpy.mgrid[10:40:10, 1:4] ZZ = XX + YY
I am not familiar with scitools material, but ndgrid seems to be equivalent to meshgrid , and BoxGrid is really a whole class that will help in this generation.
chthonicdaemon Sep 13 '12 at 10:40 2012-09-13 10:40
source share