python - logical operation on numpy array that was originally a pandas data frame -


i have 2 variables want perform on them elementwise logical operations. following error:

    tp = sum(actual & predicted) typeerror: ufunc 'bitwise_and' not supported input types, , inputs not safely coerced supported types according casting rule ''safe'' 

below code:

import pandas pd import numpy 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) 

per comments, actual , predicted both have dtype float64. problem can reproduced

in [467]: actual = np.random.random(10)  in [468]: predicted = np.random.random(10)  in [469]: actual & predicted typeerror: ufunc 'bitwise_and' not supported input types, , inputs not safely coerced supported types according casting rule ''safe'' 

& the bitwise_and operator. makes sense integers , boolean values; doesn't make sense floating point values.

you'll need explain expected compute before suggest fix.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -