I am trying to calculate F1_Score using numpy array using the code below
ypred = np.squeeze(imgs_mask_predict[jj,:,:,:])
ytrue = np.squeeze(imgs_test_mask[jj,:,:,:])
def f1_score_single(y_true, y_pred):
y_true = y_true.flatten('F')
y_pred = y_pred.flatten('F')
cross_size = len(y_true & y_pred)
if cross_size == 0: return 0.
p = 1. * cross_size / len(y_pred)
r = 1. * cross_size / len(y_true)
return (2. * (p * r) / (p + r))
I get an error
"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'' " at this line of code
cross_size = len(y_true & y_pred)
I tried to search for this error but did not get the reason and solution for this. How should I resolve this?
y_true.dtypeandy_pred.dtype?type(y_true)andy_true.shape. Now show usy_true.dtypeandy_pred.dtype. Thedtypeattribute tells you the data type of the data in the numpy array.&operator (which for numpy arrays is bitwise-and) with floating point values? That operator only makes sense (for some definition of "sense") with integer values.