Python中的网格工具(meshgrid mgrid ogrid ndgrid) [英] Mesh grid functions in Python (meshgrid mgrid ogrid ndgrid)

查看:407
本文介绍了Python中的网格工具(meshgrid mgrid ogrid ndgrid)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找与网状网格类似的功能的清晰对比.不幸的是我找不到它!

I'm looking for a clear comparison of meshgrid-like functions. Unfortunately I don't find it!

Numpy http://docs.scipy.org/doc/numpy/reference/提供

  • mgrid

ogrid

meshgrid

Scitools http://hplgit.github.io/scitools/doc /api/html/index.html 提供

Scitools http://hplgit.github.io/scitools/doc/api/html/index.html provides

  • ndgrid

boxgrid

理想情况下,总结所有这些的表格将是完美的!

Ideally a table summarizing all this would be perfect!

推荐答案

numpy.meshgrid是根据Matlab的meshgrid命令建模的.它用于向量化两个变量的函数,以便您可以编写

numpy.meshgrid is modelled after Matlab's meshgrid command. It is used to vectorise functions of two variables, so that 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]])

因此,ZZ包含放入函数中的所有xy组合.考虑一下,对于广播的numpy数组,meshgrid有点多余.这意味着您可以

So ZZ contains all the combinations of x and y put into the function. When you think about it, meshgrid is a bit superfluous for numpy arrays, as they broadcast. This means you can do

XX, YY = numpy.atleast_2d(x, y)
YY = YY.T # transpose to allow broadcasting
ZZ = XX + YY

并获得相同的结果.

mgridogrid是使用索引符号的帮助程序类,因此您可以直接在前面的示例中创建XXYY,而不必使用类似linspace的内容.产生输出的顺序相反.

mgrid and ogrid are helper classes which use index notation so that you can create XX and YY in the previous examples directly, without having to use something like linspace. The order in which the output are generated is reversed.

YY, XX = numpy.mgrid[10:40:10, 1:4]
ZZ = XX + YY # These are equivalent to the output of meshgrid

YY, XX = numpy.ogrid[10:40:10, 1:4]
ZZ = XX + YY # These are equivalent to the atleast_2d example

我对scitools的东西不熟悉,但是ndgrid似乎等同于meshgrid,而BoxGrid实际上是帮助此类生成的整个类.

I am not familiar with the scitools stuff, but ndgrid seems equivalent to meshgrid, while BoxGrid is actually a whole class to help with this kind of generation.

这篇关于Python中的网格工具(meshgrid mgrid ogrid ndgrid)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆