np.meshgrid和np.mgrid的区别

np.meshgrid

生成网格型数据

>>> import numpy as np
>>> p = np.array([2,3])
>>> p
array([2, 3])
>>> q = np.array([1, 2, 3])
>>> q
array([1, 2, 3])
>>> x, y = np.meshgrid(p, q)
>>> x
array([[2, 3],
       [2, 3],
       [2, 3]])
>>> y
array([[1, 1],
       [2, 2],
       [3, 3]])

通俗来说,p是x的行向量,q是y的列向量

mgrid

>>> import numpy as np
>>> m, n = np.mgrid[2:3, 1:3]
>>> m
array([[2, 2]])
>>> n
array([[1, 2]])
>>> m, n = np.mgrid[2:4, 1:4]
>>> m
array([[2, 2, 2],
       [3, 3, 3]])
>>> n
array([[1, 2, 3],
       [1, 2, 3]])

通俗来说,函数第一个值作为m的列向量,第二个值作为n的行向量

你可能感兴趣的:(python)