Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Python float and numpy float32

Tags:

python

numpy

What is the difference between the built in float and numpy.float32?

Example

a = 58682.7578125 print type(a) print a print type(numpy.float32(a)) print numpy.float32(a) 

Output:

<type 'float'> 58682.7578125 <type 'numpy.float32'> 58682.8 

I've found here that numpy.float32 is:

float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa

didn't find what the built in float format is.

like image 650
TheMeaningfulEngineer Avatar asked Jun 06 '13 13:06

TheMeaningfulEngineer


People also ask

Is float and float32 same?

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.

What is Numpy float32?

float32. Single precision float: sign bit, 8 bits exponent, 23 bits mantissa.

What is the difference between float and Numpy float64?

float32 and np. float64 are numpy specific 32 and 64-bit float types. Thus, when you do isinstance(2.0, np. float) , it is equivalent to isinstance(2.0, float) as 2.0 is a plain python built-in float type... and not the numpy type.

What is the difference between float 32 and 64?

float32 is a 32 bit number - float64 uses 64 bits. That means that float64's take up twice as much memory - and doing operations on them may be a lot slower in some machine architectures. However, float64's can represent numbers much more accurately than 32 bit floats. They also allow much larger numbers to be stored.


1 Answers

Python's standard float type is a C double: http://docs.python.org/2/library/stdtypes.html#typesnumeric

NumPy's standard numpy.float is the same, and is also the same as numpy.float64.

like image 147
John Zwinck Avatar answered Sep 26 '22 07:09

John Zwinck