How can unique rows be extracted from a NumPy array?

I have an issue with the code pasted below:

This code works fine, however, I find difficulty in understanding what the code is actually doing, and I can’t visualize how is it extracting unique rows from a NumPy array. Can anyone explain how to extract unique rows using this code or use another simpler example code and explain the concept to me?

1 Like

Yes, the code you attached may be difficult to understand. However, you can use the following alternate code to achieve the same thing using NumPy, and it is much easier to understand:

  • The code makes use of the np.unique() function on the input array. To find the unique rows, we specify axis=0.
  • The function returns an array containing only the unique rows of the input array, sorted in ascending order.