2016-08-04 7 views
0

theseanswersthisで提供されている提案された解決策に従っていますが、私は自分のエラーを削除するようです。Numpy polyfit ufuncのPython TypeErrorにシグネチャタイプが一致するループが含まれていない

スロープリストとvals範囲のオブジェクトタイプを変更しようとしましたが、まだエラーが表示されます。私はpolynomial.pyスクリプトに陥ったが、私はエラーに記載されているコード行を理解していない。

全体的に、グレースケール値(0-255)に基づいて8ビットのグレースケール画像を個々の配列に分割し、各値に最適な線を生成し、その線から各勾配を使います画像に最も適した全体的なラインを得るのに最も適しています。ここで

は私のコードです:

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 

はここに私のエラーです:

<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') 

答えて

1

私はこれを解決(私は願っています)、私はヴァルスの各範囲と斜面リストを反復処理することによって、新しいリストを作成し、それぞれに含まれるオブジェクトのそれぞれを浮動させる。私はすでにforループの中でそれをやっていたので、もっと早くやっておくべきだった。

関連する問題