How to convert the output of meshgrid to the corresponding array of points?

前端 未结 3 2027
自闭症患者
自闭症患者 2021-01-30 18:19

I want to create a list of points that would correspond to a grid. So if I want to create a grid of the region from (0, 0) to (1, 1), it would contain

3条回答
  •  日久生厌
    2021-01-30 18:47

    Yet another way to do it is:

    np.indices((2,2)).T.reshape(-1,2)
    

    Which can be generalized to higher dimensions, e.g.:

    In [60]: np.indices((2,2,2)).T.reshape(-1,3)
    Out[60]:
    array([[0, 0, 0],
           [1, 0, 0],
           [0, 1, 0],
           [1, 1, 0],
           [0, 0, 1],
           [1, 0, 1],
           [0, 1, 1],
           [1, 1, 1]])
    

提交回复
热议问题