I am trying to convert an array of np.string_s that are all representing numbers into floats for mathematical use. I am reading data from a fits file using pyfits.
data = read_fits(datafile)
glon = np.asarray(data['GLON'], dtype = float); glat = data['GLAT']
# heliocentric distance in kpc
D = data['D']
for i in range(len(glon)):
#glon[i] = (glon[i]).astype(float)
I have left a couple of my attempts to change the type, but float() and all similar operations I have heard of are failing. Yet I do not think I have a bogus value as I have looked through a print of the data after reading and it is all numerical.
<type 'numpy.ndarray'>.ValueError: could not convert string to floatif I attempt to convert in any way. It isunsupported operand type(s) for /: 'numpy.string_' and 'int'for my other purposes.data['GLON']. I'm guessingnp.string_. Also you could experiment with[float(i) for i in data['GLON]]` (assuming it is 1d).