Home > database >  Converting float numpy arrays to string arrays Python
Converting float numpy arrays to string arrays Python

Time:11-17

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'])

CodePudding user response:

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

CodePudding user response:

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