I am trying to write a function that initialises an array and shuffles it before returning. import numba as nb
@nb.jit(nopython=True, cache=True)
def test(x):
ind = np.array(range(len(x)))
np.random.shuffle(ind)
return ind
Error message said that I used unsupported features or data types:
NotImplementedError: range_state_int64 cannot be represented as a Numpy dtype
Does numba supports numpy.random.shuffle() or not? How to revise it? Thank you!
This actually has nothing to do with random.shuffle, because numba supports the random module out of the box.
The issue here is that numba cannot support the range object (because it is a python object) when the nopython flag has been set. Substitute range with np.arange instead:
@nb.njit(cache=True) # same as @nb.jit(nopython=True, ...)
def test(x):
ind = np.arange(len(x))
np.random.shuffle(ind)
return ind
test([1, 2, 3])
# array([1, 0, 2])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With