简体   繁体   English

Numpy polyfit ufunc中的Python TypeError不包含具有匹配签名类型的循环

[英]Python TypeError in Numpy polyfit ufunc did not contain loop with matching signature types

This has been asked before so apologies for asking again, I have followed the suggested solutions provided in these answers and this , but I'cant seem to remove my error. 之前有人问过这个问题,因此再次道歉,我遵循了这些 答案this中提供的建议解决方案,但是我似乎无法消除我的错误。

I've tried changing object type for the slope list and vals range but still I get the error. 我尝试过更改坡度列表和vals范围的对象类型,但仍然收到错误。 I ducked into the polynomial.py script but I don't understand the line of code listed in the error. 我躲到了polynomial.py脚本中,但是我不理解错误中列出的代码行。

Overall I'm trying to separate an 8-bit grayscale image into individual arrays based on the grayscale values (0-255), generate a line of best fit for each value, then use each of the slopes from the lines of best fit to get an overall line of best fit for the image. 总的来说,我正在尝试根据灰度值(0-255)将8位灰度图像分成单独的阵列,为每个值生成最合适的线,然后使用最合适的线中的每个斜率获得最适合该图像的整体线条。

Here's my code: 这是我的代码:

image = Image.open('subfram-002.tif')
im_array = np.array(image)
#print(im_array)
####
multivec = []
####
# For loop to calculate the line of best fit for each value in the    sub-frame array
arrays = [im_array] # Calling our array
vals = list(range(255)) # Range of values in array
slopes = [] # List to append each of the slopes of the line of best fit
skip = False
for i in arrays:
    for j in vals:
        index = list(zip(*np.where (j == i))) # Creating a list of the position indices for each value in the array
        in_array = np.array(index) # Updating list to array, not needed will remove

        a = list([int(i[0]) for i in index]) # Getting the first element of each tuple in the index list
        b = list([int(i[1]) for i in index]) # Getting the second element of each tuple in the index list
        # Add exception for vectors that are not generated due to values in 0-255 not being present
        if len(a) == 0:
            skip = True
        elif len(b) == 0:
            skip = True
        else:
            vec = list((np.poly1d(np.polyfit(a,b,1))).c) # Calculating list of best (1st order polynomial, consider increasing the order?)
            slope = float(vec[0]) # Getting the 1st coefficient of the line of best fit, which is the slope
            slopes.append(slope) # appending each slope to a list of slopes

print(type(slopes), type(vals))

slopes += ['0'] * (255 - len(slopes)) # Padding slope list in case less then 255 slopes generated

print(len(vals))

# Take in all of the slopes from each vector that is determined for each value
vec1 = (np.poly1d(np.polyfit(slopes,vals,1))).c # Determining the overall line of best fit for the array, using the slope of the vector as the comparator between sub-frames

Here's my error: 这是我的错误:

<class 'list'> <class 'list'>
255
Traceback (most recent call last):
  File "aryslop.py", line 53, in <module>
    vec1 = (np.poly1d(np.polyfit(slopes1,vals1,1))).c # Determining the overall line of best fit for the array, using the slope of the vector as the comparator between sub-frames
  File "/home/vanoccupanther/anaconda3/lib/python3.5/site-packages/numpy/lib/polynomial.py", line 549, in polyfit
    x = NX.asarray(x) + 0.0
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')

I solved this (I hope), I created new lists by iterating through each of the vals range and slopes list, turning each of the objects contained in each into floats. 我解决了这个问题(我希望如此),我通过遍历每个vals范围和斜率列表,并将每个对象中包含的每个对象转换为浮点数来创建新列表。 I had done that already inside my for loop so I should have just done that earlier. 我已经在for循环中完成了该操作,因此我应该早些进行。

TypeError: ufunc 'add' 不包含签名匹配类型 dtype(' <u1') dtype('<u1') dtype('<u1')< div><div id="text_translate"><p> 我是 Python 用户的初学者。 当我尝试在下面编写代码时发生错误</p><pre>import numpy as np np.array(['a', 'b', 'c']) + np.array(['d','e', 'f'])</pre><pre> TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('&lt;U1') dtype('&lt;U1') dtype('&lt;U1')</pre><p> 所以我尝试设置dtype = '&lt;U1' ,但它没有用</p><pre>import numpy as np np.array(['a', 'b', 'c'], dtype='&lt;U1') + np.array(['d','e', 'f'], dtype='&lt;U1')</pre><p> 如何无错误地连接那些 np.arrays ?</p></div></u1')> - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:ufunc &#39;add&#39; 不包含具有签名匹配类型的循环 - TypeError: ufunc 'add' did not contain a loop with signature matching types numpy.core._exceptions.UFuncTypeError: ufunc &#39;subtract&#39; 不包含具有签名匹配类型的循环 - numpy.core._exceptions.UFuncTypeError: ufunc 'subtract' did not contain a loop with signature matching types “ufunc 不包含具有签名匹配类型的循环”是什么意思? - What does "ufunc did not contain a loop with signature matching types" mean? ufunc &#39;add&#39; 不包含签名匹配类型 dtype 的循环 - ufunc 'add' did not contain a loop with signature matching types dtype 为什么 numpy 在尝试预测回归时会引发异常错误:“ufunc'add'没有包含签名匹配类型的循环”? - Why does numpy raise exception error: “ufunc 'add' did not contain a loop with signature matching types” when trying to predict a regressand? TypeError: ufunc 'add' 不包含签名匹配类型 dtype(' <u1') dtype('<u1') dtype('<u1')< div><div id="text_translate"><p> 我是 Python 用户的初学者。 当我尝试在下面编写代码时发生错误</p><pre>import numpy as np np.array(['a', 'b', 'c']) + np.array(['d','e', 'f'])</pre><pre> TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('&lt;U1') dtype('&lt;U1') dtype('&lt;U1')</pre><p> 所以我尝试设置dtype = '&lt;U1' ,但它没有用</p><pre>import numpy as np np.array(['a', 'b', 'c'], dtype='&lt;U1') + np.array(['d','e', 'f'], dtype='&lt;U1')</pre><p> 如何无错误地连接那些 np.arrays ?</p></div></u1')> - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1') numpy.core._exceptions.UFuncTypeError: ufunc &#39;add&#39; 不包含带有签名匹配的循环 - numpy.core._exceptions.UFuncTypeError: ufunc 'add' did not contain a loop with signature matching 附加字符串并添加到 dataframe 列发生“ufunc'add'没有包含签名匹配类型的循环”-错误 - Appending strings and adding to dataframe column occurs “ufunc 'add' did not contain a loop with signature matching types”-error UFuncTypeError:在列表中添加元素时,ufunc&#39;add&#39;不包含具有签名匹配类型的循环 - UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types when add element in list TypeError:ufunc&#39;add&#39;不包含带有ARIMA模型签名的循环 - TypeError: ufunc 'add' did not contain a loop with signature for ARIMA model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM