我正在尝试检查int8
s的NumPy数组中是否有数字。我试过了,但不起作用。
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))
我得到的错误是
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项。它们不会排序。
发布于 2021-04-20 19:03:56
这只是max9111的答案的一个微小的变化。稍短一点,并将要搜索的元素作为一个参数。一旦找到元素,它也会退出循环。
from numba import njit
@njit
def isin(val, arr):
for i in range(len(arr)):
if arr[i] == val:
return True
return False
https://stackoverflow.com/questions/54930852
复制相似问题