TypeError: ufunc 'add' did not contain a loop with signature matching types

后端 未结 1 810
面向向阳花
面向向阳花 2020-12-03 02:12

I am creating bag of words representation of the sentence. Then taking the words that exist in the sentence to compare to the file \"vectors.txt\", in order to get their emb

相关标签:
1条回答
  • 2020-12-03 02:48

    You have a numpy array of strings, not floats. This is what is meant by dtype('<U9') -- a little endian encoded unicode string with up to 9 characters.

    try:

    return sum(np.asarray(listOfEmb, dtype=float)) / float(len(listOfEmb))
    

    However, you don't need numpy here at all. You can really just do:

    return sum(float(embedding) for embedding in listOfEmb) / len(listOfEmb)
    

    Or if you're really set on using numpy.

    return np.asarray(listOfEmb, dtype=float).mean()
    
    0 讨论(0)
提交回复
热议问题