Numpy Mgrid and Meshgrid. Conversion between Meshgrid and Mgrid

Опубликовано: 28 Июнь 2026
на канале: Pythonika
1,530
31

Zen of Python advertise few principles, one of which states, that “There should be one– and preferably only one –obvious way to do it.” And from my point of view mgrid and meshgrid functions from NumPy are breaking this principle.
In this tutorial, I will explain how to use mgrid, meshgrid and what is the difference between them. I also will explain how to convert data from mgrid to meshgrid and back.
I will give you an idea, how to read external datafiles and understand what format is mgrid or meshgrid.
Read NumPy guide here: http://mycoding.uk/a/python_numpy.html
This guide will be interesting for Python coders who working with grid data, calculating vector and scalar fields.
How to convert between mgrid and meshgrid: http://mycoding.uk/a/numpy__what_the_...
Example of calculations with mgrid:    • 3 Dimensional Electric Field Lines with Ma...  
example of calculations with meshgrid:    • Electric field intensity and Electric fiel...  
Video content:
0:00 – Introduction
0:06 – Parameters of initial domain
0:30 – 1-dimensional case
0.52 – 2-dimensional case
1:15 – “Physical” sense behind mgrid function
2:07 – The same with meshgrid
2:57 – 2D case difference between mgrid and meshgrid
3:35 – 3D case with mgrid and meshgrid
4:45 – 3D case converting between mgrid and meshgrid
5:09 – 4D case
5:45 – A bit about data alignment.
So, after this very long discussion, I can tell you, that my choice is MGRID!
#numpy #pythoncoding #electricfield