首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >数组中的Python Numba值

数组中的Python Numba值
EN

Stack Overflow用户
提问于 2019-03-01 01:07:32
回答 1查看 1.1K关注 0票数 3

我正在尝试检查int8s的NumPy数组中是否有数字。我试过了,但不起作用。

代码语言:javascript
复制
from numba import njit
import numpy as np

@njit
def c(b):
    return 9 in b

a = np.array((9, 10, 11), 'int8')
print(c(a))

我得到的错误是

代码语言:javascript
复制
Invalid use of Function(<built-in function contains>) with argument(s) of type(s): (array(int8, 1d, C), Literal[int](9))
 * parameterized
In definition 0:
    All templates rejected with literals.
In definition 1:
    All templates rejected without literals.
In definition 2:
    All templates rejected with literals.
In definition 3:
    All templates rejected without literals.
In definition 4:
    All templates rejected with literals.
In definition 5:
    All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: typing of intrinsic-call at .\emptyList.py (6)

我如何在保持性能的同时修复这个问题?将检查数组中的两个值,1和-1,长度为32项。它们不会排序。

EN

回答 1

Stack Overflow用户

发布于 2021-04-20 19:03:56

这只是max9111的答案的一个微小的变化。稍短一点,并将要搜索的元素作为一个参数。一旦找到元素,它也会退出循环。

代码语言:javascript
复制
from numba import njit

@njit
def isin(val, arr):
    for i in range(len(arr)):
        if arr[i] == val:
            return True
    return False
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54930852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档