How to force python float operation on float32 rather than float64?
28,441
Will numpy.float32 help?
>>>PI=3.1415926535897
>>> print PI*PI
9.86960440109
>>> PI32=numpy.float32(PI)
>>> print PI32*PI32
9.86961
If you want to do math operation on float32, convert the operands to float32 may help you.
Author by
Samuel
Updated on September 29, 2020Comments
-
Samuel over 3 years
I want to do some math operations (+, -, *, /) on
float32
rather than onfloat64
type. I need do these operations onnumber
ornumpy.array
, and also some numpy math functions, such assqrt mean
. How do I do this?