from numba import njit
def unique_np(ar):
std = np.sort(ar)
flag = np.concatenate((np.array([True]), std[1:] != std[:-1]))
return std[flag]
unique_jit = njit(unique_np)
# Check they both work
inp = np.array([6, 1, 2, 2, 3])
assert (unique_jit(inp) == unique_np(inp)).all()
assert (np.unique(inp) == unique_np(inp)).all()
nr.seed(0)
ri = nr.randint(0, high=1000, size=10000)
assert (unique_jit(ri) == np.unique(ri)).all() # checking again...
%timeit unique_np(ri) # => 1000 loops, best of 3: 427 µs per loop
%timeit unique_jit(ri) # => 1000 loops, best of 3: 594 µs per loop
--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.
To post to this group, send email to numba...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/4bf4ffc5-2b78-4e0a-a186-fbceaef76f2c%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
Warning
Sorting may be slightly slower than Numpy’s implementation.