2013-06-06 13 views
20

Was ist der Unterschied zwischen den eingebauten float und numpy.float32?Unterschied zwischen Python float und numpy float32

Beispiel

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

Ausgang:

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

Ich habe festgestellt, dass herenumpy.float32 ist:

float32 einfache Genauigkeit float: Vorzeichenbit, 8 Bit Exponent, 23 Bits Mantisse

nicht gefunden, was das eingebaute float Format ist.

+0

In Ihrem Beispiel 'float_32 = np.float32 (a); drucken (float_32 == a)' druckt True - ?? –

Antwort

17

Python Standard float Typ ist ein C double: http://docs.python.org/2/library/stdtypes.html#typesnumeric

NumPy Standard numpy.float gleich ist, und ist auch die gleiche wie numpy.float64.

+16

Beachten Sie, dass 'numpy.float' nur ein Alias ​​für Pythons' float'-Typ ist. Es ist kein numpiger Skalartyp wie 'numpy.float64'. Der Name wird nur aus Gründen der Abwärtskompatibilität mit einer sehr frühen Version von numpy offen gelegt, die 'numpy.float64' fälschlicherweise als' numpy.float' ausgab, was zu Problemen führte, wenn Leute 'von numpy import *' machten. –

Verwandte Themen