Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It is possible to change the data type of an array from 'O' to 'float64', but requires casting the elements of the array to the new data type.

For example:

import numpy as np

arr = np.array(['1.0', '2.0', '3.0'], dtype='O')
print(arr)
# ['1.0' '2.0' '3.0']

arr = arr.astype('float64')
print(arr)
# [1. 2. 3.]

In this example, the array is initially created with the data type 'O' (object). We then cast the array to 'float64' using the astype() method, which converts the elements of the array to the new data type. The resulting array has the desired data type of 'float64'.