TypeError: ufunc 'subtract' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1')

I got the same error, but in my case I am subtracting dict.key from dict.value. I have fixed this by subtracting dict.value for corresponding key from other dict.value.

cosine_sim = cosine_similarity(e_b-e_a, w-e_c)

here I got error because e_b, e_a and e_c are embedding vector for word a,b,c respectively. I didn't know that 'w' is string, when I sought out w is string then I fix this by following line:

cosine_sim = cosine_similarity(e_b-e_a, word_to_vec_map[w]-e_c)

Instead of subtracting dict.key, now I have subtracted corresponding value for key


Why is it applying diff to an array of strings.

I get an error at the same point, though with a different message

In [23]: a=np.array([u'A' u'B' u'C' u'D' u'E'])

In [24]: np.diff(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-9d5a62fc3ff0> in <module>()
----> 1 np.diff(a)

C:\Users\paul\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\lib\function_base.pyc in diff(a, n, axis)
   1112         return diff(a[slice1]-a[slice2], n-1, axis=axis)
   1113     else:
-> 1114         return a[slice1]-a[slice2]
   1115 
   1116 

TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'numpy.ndarray' 

Is this a array the bins parameter? What does the docs say bins should be?


I had a similar issue where an integer in a row of a DataFrame I was iterating over was of type numpy.int64. I got the

TypeError: ufunc 'subtract' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1')

error when trying to subtract a float from it.

The easiest fix for me was to convert the row using pd.to_numeric(row).