close

[Solved] Numpy.dot Type: Cannot cast array data from dtype(‘float64’) to dtype(‘S32’) according to the rule ‘safe’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Numpy.dot Type: Cannot cast array data from dtype(‘float64’) to dtype(‘S32’) according to the rule ‘safe’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Numpy.dot Type: Cannot cast array data from dtype(‘float64’) to dtype(‘S32’) according to the rule ‘safe’ Error Occurs?

Today I get the following error Numpy.dot Type: Cannot cast array data from dtype(‘float64’) to dtype(‘S32’) according to the rule ‘safe’ in python.

How To Solve Numpy.dot Type: Cannot cast array data from dtype(‘float64’) to dtype(‘S32’) according to the rule ‘safe’ Error ?

  1. How To Solve Numpy.dot Type: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe' Error ?

    To Solve Numpy.dot Type: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe' Error Just taking the input from BrenBarn and Warren Weckesser to provide a code snippet which should run (by converting your strings to float):

  2. Numpy.dot Type: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'

    To Solve Numpy.dot Type: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe' Error Just taking the input from BrenBarn and Warren Weckesser to provide a code snippet which should run (by converting your strings to float):

Solution 1

Just taking the input from BrenBarn and Warren Weckesser to provide a code snippet which should run (by converting your strings to float):

a = map(lambda x: float(x),a)
b = map(lambda x: float(x),b)
np.dot(a,b.T)

or simpler as suggested by @JLT

a = map(float,a)
b = map(float,b)
np.dot(a,b.T)

But as Warren Weckesser already said, you should check the types of the array, most likely one already contains floats.

Solution 2

Try converting whole numpy array into float Example:

train = train.astype(float)
train_target = train_target.astype(float)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read