question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numpy array inconsistency

See original GitHub issue

Reporting a bug

  • I have tried using the latest released version of Numba (most recent is visible in the change log (https://github.com/numba/numba/blob/main/CHANGE_LOG).
  • I have included a self contained code sample to reproduce the problem. i.e. it’s possible to run as ‘python bug.py’.

The following function works fine outside of numba:

def myfun():
    y=np.zeros(10)
    y[0]=np.array([3])
    return y

However it fails with numba, as shown here:

@jit(nopython=True)
def myfun():
    y=np.zeros(10)
    y[0]=np.array([3])
    return y

But can be made to work using:

@jit(nopython=True)
def myfun():
    y=np.zeros(10)
    y[0]=np.array([3])[0]
    return y

This is awkward behaviour - would be nice if it could be solved. Thanks!

(I am using python 3.10 in conda, with numpy v 1.21.2 and numba v 0.55.0 which is the latest version available in conda). Use the following import statements:

import numpy as np
from numba import jit

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
esccommented, Feb 8, 2022

@amireson I have labelled it accordingly until such a time as a champion appears to fix it.

0reactions
stuartarchibaldcommented, Feb 14, 2022

Further note. I think a way to write this that will work for any dimension single value array is using np.take:

from numba import njit
import numpy as np

@njit
def foo(x):
    y = np.zeros(4)
    y[0] = np.take(x, 0)
    return y

tmp = np.array(3)
for i in range(5):
    print(tmp)
    print(foo(tmp))
    tmp = np.expand_dims(tmp, 0)
Read more comments on GitHub >

github_iconTop Results From Across the Web

python 3.x - numpy arrays are inconsistent - Stack Overflow
I've figured it out. My dataset had data points that weren't exactly 520 in length, so numpy was unable to create a 2d...
Read more >
Dunder Data - Found a rare inconsistency with numpy You ...
Found a rare inconsistency with numpy You can convert a float array containing missing values to int. missing value replaced with smallest possible...
Read more >
scipy.cluster.hierarchy.maxinconsts — SciPy v1.9.3 Manual
The inconsistency matrix. ... A monotonic (n-1) -sized numpy array of doubles. ... from scipy.cluster.hierarchy import median, inconsistent, maxinconsts ...
Read more >
Inconsistent manual computing of cumsumming a array in ...
[Solved]-Inconsistent manual computing of cumsumming a array in Python-numpy ... x is symmetric, but the cumsum is not. ... The first column is...
Read more >
Writing custom array containers — NumPy v1.25.dev0 Manual
!= self._N: ... raise TypeError("inconsistent sizes") ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found