Skip to content
Advertisement

Correct usage of numpy.vstack with python’s numba

I am currently trying to speed up some python code using numba. According to the documentation of numba, numpy.meshgrid is not supported but numpy.vstack is. So I replaced the meshgrid call by vstack which works fine when not using numba. It does not work, however, when using numba.

Here is the code:

JavaScript

And here is the error message:

JavaScript

It sounds to me that the way I am using vstack is not supported, is that correct?

The versions I am using:

JavaScript

Update1: Using np.concatenate( n*[[x]] ) results in a similar error:

JavaScript

Update2: Using np.hstack( n*[y[:,np.newaxis]] ) results in the same error as the original error.

Using y.reshape(-1,1).repeat(n,1) results in the following error:

JavaScript

Advertisement

Answer

If you look at the error message carefully, you will see that it says

JavaScript

getitem is how numba compiles the [] operator. The signature shows that numba does not support a call like array[slice, None]. Specifically, the problem is

JavaScript

Numba does support the reshape operation and repeat, but without an axis argument, so you can change that line to

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement