2015-06-25 100 views
0

我有兩個變量,我想對它們執行元素邏輯運算。然而,我得到以下錯誤:原始熊貓數據幀的numpy數組的邏輯運算

tp = sum(actual & predicted) 
TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' 

下面是我的代碼:

import pandas as pd 
import numpy as np 

train = 'train.tsv' 
submission = 'submission1234.csv' 

trainSearchStream = pd.read_csv(train,sep='\t') 

sample = pd.read_csv(path + 'sampleSubmission.csv') 
preds = np.array(pd.read_csv(submission, header = None)) 
index = sample.ID.values - 1 
sample['IsClick'] = preds[index] 

actual = np.array(trainSearchStream['IsClick'].dropna()) 
predicted = np.array(sample['IsClick']) 

tp = sum(actual & predicted) 
+1

請發佈'actual.dtype'和'predicted.dtype'。 – unutbu

+0

我得到float64兩個@unutbu – MAS

+0

另外,我得到以下:打印(類型(實際)) 打印(類型(預測)) <類型 'numpy.ndarray'> <類型 'numpy.ndarray'> – MAS

回答

1

%的意見,actualpredicted都具有D型float64。 所以這個問題可以簡單地用

轉載
In [467]: actual = np.random.random(10) 

In [468]: predicted = np.random.random(10) 

In [469]: actual & predicted 
TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs 
could not be safely coerced to any supported types according to the casting rule 
''safe'' 

&the bitwise_and operator。它對整數和布爾值是有意義的;它爲doesn't make sense浮點值。

在我們提出修復建議之前,您需要解釋您希望計算的結果。