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?
float32 is less accurate but faster than float64, and flaot64 is more accurate than float32 but consumes more memory. If accuracy is more important than speed , you can use float64. and if speed is more important than accuracy, you can use float32.
float is one of the available numeric data types in Go used to store decimal numbers. float32 is a version of float that stores decimal values composed of 32 bits of data.
At least on intel, float64 should be faster than float32 since all math is done on the fpu in 64 bits, so it needs to be converted, but the memory bus also comes into play.
Python's floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent to np. float64 . In some unusual situations it may be useful to use floating-point numbers with more precision.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With