georgehere
georgehere

Reputation: 630

Converting float numpy arrays to string arrays Python

How would I be able to turn all float numpy arrays into strings arrays?

import numpy as np 

floats = np.array([1,3.4,0.678,11.1])

Expected output:

np.array(['1','3.4','0.678','11.1'])

Upvotes: 0

Views: 81

Answers (2)

alphaBetaGamma
alphaBetaGamma

Reputation: 677

The simplest way:

np.array([1,3.4,0.678,11.1]).astype(str)

output:

array(['1.0', '3.4', '0.678', '11.1'], dtype='<U32')

Upvotes: 2

User
User

Reputation: 826

strings = [str(value) for value in floats]

Upvotes: 0

Related Questions