def nsmallest(arr, n, keep='first'):
 if (keep == 'last'):
  arr = arr[::(-1)]
 narr = len(arr)
 n = min(n, narr)
 sdtype = str(arr.dtype)
 arr = arr.view(_dtype_map.get(sdtype, sdtype))
 kth_val = algos.kth_smallest(arr.copy(), (n - 1))
 return _finalize_nsmallest(arr, kth_val, n, keep, narr)

def nsmallest ( arr , n , keep = 'first' ) : if ( keep == 'last' ) : arr = arr [ : : ( - 1 ) ] narr = len ( arr ) n = min ( n , narr ) sdtype = str ( arr . dtype ) arr = arr . view ( _dtype_map . get ( sdtype , sdtype ) ) kth_val = algos . kth_smallest ( arr . copy ( ) , ( n - 1 ) ) return _finalize_nsmallest ( arr , kth_val , n , keep , narr )
find the n smallest elements in a dataset .