Created
          October 20, 2015 00:14 
        
      - 
      
- 
        Save alimuldal/f900f2a3e676348bc34b to your computer and use it in GitHub Desktop. 
    numpy unique rows
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def unique_rows(a, **kwargs): | |
| rowtype = np.dtype((np.void, a.dtype.itemsize * a.shape[1])) | |
| b = np.ascontiguousarray(a).view(rowtype) | |
| return_index = kwargs.pop('return_index', False) | |
| out = np.unique(b, return_index=True, **kwargs) | |
| idx = out[1] | |
| uvals = a[idx] | |
| if (not return_index) and (len(out) == 2): | |
| return uvals | |
| elif return_index: | |
| return (uvals,) + out[1:] | |
| else: | |
| return (uvals,) + out[2:] | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment