我想要对元素逻辑运算执行两个变量。但是我收到以下错误:
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)
答案 0 :(得分:1)
根据评论,actual
和predicted
都有dtype 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。
在我们提出修复建议之前,您需要先解释一下您的预期。