Slice a 3d numpy array using a 1d lookup between indices

Slice a 3d numpy array using a 1d lookup between indices import numpy as np a = np.arange(12).reshape(2, 3, 2) b = np.array([2, 0]) b maps i to j where i and j are the first 2 indexes of a, so ​a[i,j,…

How do I vectorize a function which has multiple outputs with Numba?

For example, I want to vectorize the following function: @nb.njit(nb.types.UniTuple(nb.float64,2)(nb.float64, nb.float64)) def add_subtract(x,y): return x+y, x-y However, when I use @numba….

Using numpy random choice in numba

I’m trying to rewrite some of my code using numba (version 0.52, on windows 10, 64-bit), however I get an error that I don’t understand using numpy random choice. Numpy random choice should be working …

Have trouble using numba atomic operation functions (cuda.atomic.compare_and_swap)

I am trying to use Numba to write cuda kernels for my code. And somehow I wanna use the atomic operation in part of my code and I wrote a test kernel to see how cuda.atomic.compare_and_swap works. On …

convert float to string numba python numpy array

I am running a @nb.njit function within which I am trying to put an integer within a string array. import numpy as np import numba as nb @nb.njit(nogil=True) def func(): my_array = np.empty(6, …

Numba failure with np.mean

For some reason, numba fails when I add in a axis argument to np.mean. For instance, this gives an error – import numpy as np from numba import jit @jit(nopython=True) def num_prac(a): return …