. Advertisement .
..3..
. Advertisement .
..4..
The error
TypeError: Cannot cast array data from dtype('float64')
to dtype('S32') according to the rule 'safe'
occurred when I use np.dot(a,b.T) in NumPy version 1.11.0. I’ve tried to fix it for some days but have not resolved it yet. Can someone suggest a relevant solution to fix the cannot cast array data from dtype(‘float64’) to dtype(‘<u32’) according to the rule ‘safe’ issue? Much appreciate your support.
The cause:
You get trouble with ”cannot cast array data from dtype(‘float64’) to dtype(‘<u32’) according to the rule ‘safe’” error because the data of dtype(‘float64’) is strings but dtype(‘<u32’) requires float.
Solution:
You can solve this problem by changing your strings to floats, the following code snippet works well based on the input from BrenBarn and Warren Weckesser:
Or you can do simply as below:
However, you should check all the sorts of the array, probably one of them includes floats as Warren Weckesser has already indicated.
You can convert whole numpy array to float example: