How do I convert a numpy
array
from type 'float64'
to type 'float'
? Specifically, how do I convert an entire array
with dtype
'float64'
to have dtype
'float'
? Is this possible? The answer for scalars in the thought-to-be duplicate question above does not address my question.
Consider this:
>>> 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'>
If you're unsure why I might want to do this, see this question and its answers.