[英]logical operation on numpy array that was originally a pandas data frame
我有两个要对它们执行元素逻辑操作的变量。 但是我得到以下错误:
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)
根据注释, 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''
&
是bitwise_and
运算符 。 它对于整数和布尔值有意义; 对于浮点值没有意义 。
您可能需要先解释一下预期的计算结果,然后才能提出修复建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.