0

I have two variables that i want to perform on them elementwise logical operations. however I get the following error:

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

Below is my code:

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)
MAS
  • 4,503
  • 7
  • 32
  • 55

1 Answers1

1

Per the comments, actual and predicted both have dtype float64. So the problem can be reproduced simply with

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

& is the bitwise_and operator. It makes sense for integers and boolean values; it doesn't make sense for floating point values.

You'll need to explain what you expected this to compute before we could suggest a fix.

Community
  • 1
  • 1
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677