Ask Your Question
3

Is it not possible to change the data type of an array from 'O' to 'float64'?

asked 2022-09-09 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-06-29 14:00:00 +0000

lalupa gravatar image

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'.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-09 11:00:00 +0000

Seen: 20 times

Last updated: Jun 29 '21