Updating 1d array with 0d array fails
See original GitHub issueReporting a bug
I tried writing data to an output array that was created in a Numba-compiled function. This failed under some conditions, where a 1d array needed to be populated with a 0d array. A minimal working example is:
@nb.njit
def f(arr):
out = np.zeros((1,))
out[0] = arr
return out
f(np.array(1.))
# expect output: array([1.])
Instead of giving the expected output (which is returned without using numba), I get the following error:
No implementation of function Function(<built-in function setitem>) found for signature:
>>> setitem(array(float64, 1d, C), Literal[int](0), array(float64, 0d, C))
I here use numba version 0.50.1, which I believe is the current one.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Python, numpy; How to best deal with possible 0d arrays
I use the numpy.asarray function to force the inputs into the form I want, conveniently with no duplication for things that are already...
Read more >the absolute basics for beginners — NumPy v1.25.dev0 Manual
How to convert a 1D array into a 2D array (how to add a new axis to an array)#. This section covers np.newaxis...
Read more >NumPy Creating Arrays - W3Schools
An array that has 0-D arrays as its elements is called uni-dimensional or 1-D array. These are the most common and basic arrays....
Read more >NumPy array reshape (Shape transformation without data ...
The method reshape() will return a reshaped array with the same data. Reshape 1d to 2d. To convert 1D array to 2D array,...
Read more >NumPy: zeros() function - w3resource
NumPy array creation: zeros() function, example - Return a new array of given shape and type, filled with zeros.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I ended up writing a small wrapper function that turns 0d arrays into scalars:
This helps to avoid the bug, but is obviously not a long-term solution.
Thanks for closing @david-zwicker!