Come si converte un numpy
dal tipo 'float64'
al tipo 'float'
? In particolare, come faccio a convertire un'intera array
con dtype
'float64'
avere dtype
'float'
? È possibile? La risposta per gli scalari nella domanda duplicata sopra descritta non risolve la mia domanda.Come convertire un array numpy da 'float64' a 'float'
Considerate questo:
>>> type(my_array[0])
<type 'numpy.float64'>
>>> # Let me try to convert this to 'float':
>>> new_array = my_array.astype(float)
>>> type(new_array[0])
<type 'numpy.float64'>
>>> # No luck. What about this:
>>> new_array = my_array.astype('float')
>>> type(new_array[0])
<type 'numpy.float64'>
>>> # OK, last try:
>>> type(np.inf)
<type 'float'>
>>> # Yeah, that's what I want.
>>> new_array = my_array.astype(type(np.inf))
>>> type(new_array[0])
<type 'numpy.float64'>
Se non siete sicuri perché potrei voler fare questo, vedere this question e le sue risposte.
quanto ne sappia '' float' e float64' sono equivalenti a NumPy. – farenorth
@farenorth suppongo che non abbiate fatto clic sulla domanda collegata? – dbliss
possibile duplicato di [Conversione di dtypes numpy in tipi nativi di python] (http://stackoverflow.com/questions/9452775/converting-numpy-dtypes-to-native-python-types) – tzaman