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.

Share:
28,441
Samuel
Author by

Samuel

Updated on September 29, 2020

Comments

  • Samuel
    Samuel over 3 years

    I want to do some math operations (+, -, *, /) on float32 rather than on float64 type. I need do these operations on number or numpy.array, and also some numpy math functions, such as sqrt mean. How do I do this?