Sorting a 2D numpy array by multiple axes

前端 未结 7 2060
小蘑菇
小蘑菇 2020-11-27 11:23

I have a 2D numpy array of shape (N,2) which is holding N points (x and y coordinates). For example:

array([[3, 2],
       [6, 2],
       [3, 6],
       [3,          


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 11:52

    The numpy_indexed package (disclaimer: I am its author) can be used to solve these kind of processing-on-nd-array problems in an efficient fully vectorized manner:

    import numpy_indexed as npi
    npi.sort(a)  # by default along axis=0, but configurable
    

提交回复
热议问题