Python 我如何解决这个问题-无效使用函数
我在使用python包时遇到了一个我不理解的问题。错误显示:Python 我如何解决这个问题-无效使用函数,python,arrays,numba,Python,Arrays,Numba,我在使用python包时遇到了一个我不理解的问题。错误显示: TypingError: Invalid use of Function(<built-in function setitem>) with argument(s) of type(s): (array(float64, 3d, C), array(bool, 3d, C), Literal[int](0)) * parameterized In definition 0: All templates rejec
TypingError: Invalid use of Function(<built-in function setitem>) with argument(s) of type(s): (array(float64, 3d, C), array(bool, 3d, C), Literal[int](0))
* 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:
TypeError: unsupported array index type array(bool, 3d, C) in [array(bool, 3d, C)]
raised from C:\Users\sw14928\AppData\Local\Continuum\anaconda3\lib\site-packages\numba\typing\arraydecl.py:71
In definition 5:
TypeError: unsupported array index type array(bool, 3d, C) in [array(bool, 3d, C)]
raised from C:\Users\sw14928\AppData\Local\Continuum\anaconda3\lib\site-packages\numba\typing\arraydecl.py:71
In definition 6:
All templates rejected with literals.
In definition 7:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
TypingError:函数()的类型参数使用无效:(数组(float64,3d,C)、数组(bool,3d,C)、文字[int](0))
*参数化
在定义0中:
所有模板均拒绝使用文字。
在定义1中:
拒绝所有没有文字的模板。
在定义2中:
所有模板均拒绝使用文字。
在定义3中:
拒绝所有没有文字的模板。
在定义4中:
TypeError:[数组(bool,3d,C)]中不支持的数组索引类型数组(bool,3d,C)
从C:\Users\sw14928\AppData\Local\Continuum\anaconda3\lib\site packages\numba\typing\arraydecl.py:71引发
在定义5中:
TypeError:[数组(bool,3d,C)]中不支持的数组索引类型数组(bool,3d,C)
从C:\Users\sw14928\AppData\Local\Continuum\anaconda3\lib\site packages\numba\typing\arraydecl.py:71引发
在定义6中:
所有模板均拒绝使用文字。
在定义7中:
拒绝所有没有文字的模板。
此错误通常由传递指定函数不支持的类型的参数引起。
我的代码如下所示:
@njit
def kaczmarz(finalArray,responseArray):
#KaczResult = np.zeros_like(finalArray)#convolve(sourceOntable, response, method = 'direct', mode='same')
solution = np.zeros_like(finalArray)
#solution = finalArray
#remnants = np.zeros_like(finalArray)
widthFinalArray = finalArray.shape[0]
depthFinalArray = finalArray.shape[1]
widthRes = responseArray.shape[0]
depthRes = responseArray.shape[1]
xRad = int(widthRes/ 2)
yRad = int(depthRes/ 2)
#usefulResponseIndicies = response>0
rawValues = widthFinalArray * depthFinalArray * finalArray.shape[2]
damping = 0.01
for i in range(5000):
print(i)
update = np.zeros_like(solution)
count = 0
for x in range(finalArray.shape[0]):
for y in range(finalArray.shape[1]):
#randomPoint = np.random.randint(rawValues)
#coords = np.unravel_index(randomPoint, finalArray.shape)
#x = coords[0]
#y = coords[1]
x = np.random.randint(finalArray.shape[0])
y = np.random.randint(finalArray.shape[1])
#print(x,y,z)
x1 = x-xRad
if x1 < 0: x1 = 0
if x1 > widthFinalArray: x1 = widthFinalArray
x2 = xRad+x
if x2 < 0: x2 = 0
if x2 > widthFinalArray: x2 = widthFinalArray
x3 = xRad-x
if x3 < 0: x3 = 0
if x3 > widthRes: x3 = widthRes
x4 = xRad-x+widthFinalArray
if x4 < 0: x4 = 0
if x4 > widthRes: x4 = widthRes
y1 = y-yRad
if y1 < 0: y1 = 0
if y1 > depthFinalArray: y1 = depthFinalArray
y2 = yRad+y
if y2 < 0: y2 = 0
if y2 > depthFinalArray: y2 = depthFinalArray
y3 = yRad-y
if y3 < 0: y3 = 0
if y3 > depthRes: y3 = depthRes
y4 = yRad-y+depthFinalArray
if y4 < 0: y4 = 0
if y4 > depthRes: y4 = depthRes
subSection = solution[x1:x2+1, y1:y2,0]
#shape = np.shape(subSection)
#test = np.sum(subSection)
subResponse = responseArray[x3:x4,y3:y4]
KaczResult = np.sum(subResponse * subSection)
remnant = finalArray[x,y,0]-KaczResult
subUpdate = subResponse*remnant
#print(np.max(subResponse))
#print(np.max(subResponse))
update[x1:x2+1, y1:y2,0] += subUpdate
count += 1
solution[solution < 0] = 0
solution += damping*update/count
return solution
@njit
def kaczmarz(最终结果,响应日期):
#KaczResult=np.zeros_like(finalArray)#卷积(sourceOntable,response,method='direct',mode='same')
解=np.类零(finalArray)
#溶液=最终射线
#残余=np.类零(最终射线)
宽度finalArray=finalArray.shape[0]
depthFinalArray=finalArray.shape[1]
widthRes=responseArray.shape[0]
depthRes=responseArray.shape[1]
xRad=int(宽度/2)
yRad=int(深度/2)
#UsefulResponseIndicaties=响应>0
rawValues=widthFinalArray*depthFinalArray*finalArray.shape[2]
阻尼=0.01
对于范围(5000)内的i:
印刷品(一)
更新=np.类零(解决方案)
计数=0
对于范围内的x(最终射线形状[0]):
对于范围内的y(最终射线形状[1]):
#randomPoint=np.random.randint(原始值)
#coords=np.Unlavel_索引(随机点,最终射线形状)
#x=坐标[0]
#y=坐标[1]
x=np.random.randint(finalArray.shape[0])
y=np.random.randint(finalArray.shape[1])
#打印(x、y、z)
x1=x-xRad
如果x1<0:x1=0
如果x1>widthFinalArray:x1=widthFinalArray
x2=xRad+x
如果x2<0:x2=0
如果x2>widthFinalArray:x2=widthFinalArray
x3=xRad-x
如果x3<0:x3=0
如果x3>widthRes:x3=widthRes
x4=x射线-x射线+宽度最终射线
如果x4<0:x4=0
如果x4>widthRes:x4=widthRes
y1=y-yRad
如果y1<0:y1=0
如果y1>depthFinalArray:y1=depthFinalArray
y2=yRad+y
如果y2<0:y2=0
如果y2>depthFinalArray:y2=depthFinalArray
y3=yRad-y
如果y3<0:y3=0
如果y3>深度:y3=深度
y4=yRad-y+深度最终射线
如果y4<0:y4=0
如果y4>深度:y4=深度
分段=溶液[x1:x2+1,y1:y2,0]
#形状=np.形状(小节)
#测试=np.总和(小节)
子响应=响应阵列[x3:x4,y3:y4]
KaczResult=np.和(子响应*小节)
残余=最终射线[x,y,0]-KaczResult
子更新=子响应*剩余
#打印(np.max(子响应))
#打印(np.max(子响应))
更新[x1:x2+1,y1:y2,0]+=子更新
计数+=1
溶液[溶液<0]=0
解决方案+=阻尼*更新/计数
返回溶液
嘿,请指出第71行的代码。如果你仔细阅读你的错误,它会说这一行是原因。从C:\Users\sw14928\AppData\Local\Continuum\anaconda3\lib\site packages\numba\typing\arraydecl.py:71引发发布所有代码可能没有帮助,使问题难以阅读。您好,第71行没有代码。左边的目录似乎不存在。谢谢您输入的finalArray
和responseArray
是什么类型和形状?如果发布如此大的代码片段,最好添加一些虚拟数据,以便人们能够重现错误的原因