Mesh grid functions in Python (meshgrid mgrid ogrid ndgrid)

后端 未结 2 1716
星月不相逢
星月不相逢 2021-01-29 19:06

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/ provides

  • <
2条回答
  •  孤街浪徒
    2021-01-29 20:00

    np.mgrid and np.meshgrid() do the same thing but the first and the second axis are swapped:

    # 3D
    d1, d2, d3 = np.mgrid[0:10, 0:10, 0:10]
    d11, d22, d33 = np.meshgrid(np.arange(10),np.arange(10),np.arange(10))
    np.array_equal(d1,d11)
    

    yields False. Just swap the first two dimensions:

    d11 = np.transpose(d11,[1,0,2])
    np.array_equal(d1,d11)
    

    yields True.

提交回复
热议问题