我有以下数组:
import numpy as np
from numba import njit
test_array = np.random.rand(4, 10)
我创建了一个“jitted”函数,用于分割数组,然后执行一些操作:
@njit(fastmath = True)
def test_function(array):
test_array_sliced = test_array[[0,1,3]]
return test_array_sliced
但是,Numba抛出以下错误:
In definition 11:
TypeError: unsupported array index type list(int64) in [list(int64)]
raised from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numba/typing/arraydecl.py:71
This error is usually caused by passing an argument of a type that is unsupported by the named function.
我尝试使用np.delete
删除不需要的行,但由于必须指定axis
Numba,因此会引发以下错误:
@njit(fastmath = True)
def test_function(array):
test_array_sliced = np.delete(test_array, obj = 2, axis = 0)
return test_array_sliced
In definition 1:
TypeError: np_delete() got an unexpected keyword argument 'axis'
raised from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numba/typing/templates.py:475
This error is usually caused by passing an argument of a type that is unsupported by the named function.
你知道如何在Numba下提取特定的行吗?你知道吗
Numba不支持numpy fancy索引。我不能100%确定您的实际用例是什么样的,但一个简单的方法是:编辑:@kwinkunks是正确的,我最初的回答是错误的,不支持花哨的索引。这是在一系列有限的情况下,包括这一个。你知道吗
我认为如果使用数组而不是列表进行索引,它将起作用(似乎建议使用soin the docs):
(我将要切片的数组更改为
array
,这是传递给函数的内容。也许是故意的,但要小心全局的!)你知道吗相关问题 更多 >
编程相关推荐