Make a simpler array from the list:
In [26]: features = ['20.57', '17.77', '132.9', '0.07017', '0.1812', '0.667']
In [27]: features
Out[27]: ['20.57', '17.77', '132.9', '0.07017', '0.1812', '0.667']
In [28]: features = np.array(features)
In [29]: features
Out[29]:
array(['20.57', '17.77', '132.9', '0.07017', '0.1812', '0.667'],
dtype='<U7')
Note that this is an array of strings
I can use astype to make a NEW array of floats:
In [30]: features.astype(float)
Out[30]:
array([ 2.05700000e+01, 1.77700000e+01, 1.32900000e+02,
7.01700000e-02, 1.81200000e-01, 6.67000000e-01])
but that does not change the original features array. It is still strings.
In [31]: features
Out[31]:
array(['20.57', '17.77', '132.9', '0.07017', '0.1812', '0.667'],
dtype='<U7')
I'd have to reassign the features variable to get a new float array
In [32]: features = features.astype(float)
In [33]: features
Out[33]:
array([ 2.05700000e+01, 1.77700000e+01, 1.32900000e+02,
7.01700000e-02, 1.81200000e-01, 6.67000000e-01])
I could have gone directly from the list of strings to an array of floats with:
In [34]: features = ['20.57', '17.77', '132.9', '0.07017', '0.1812', '0.667']
In [35]: features = np.array(features,float)
In [36]: features
Out[36]:
array([ 2.05700000e+01, 1.77700000e+01, 1.32900000e+02,
7.01700000e-02, 1.81200000e-01, 6.67000000e-01])
But if there are any strings in the list that can't be converted to a float I'll either get an error or a string array.
Also I can't make the change in-place or piecemeal
In [40]: features[1] = float(features[1])
In [41]: features
Out[41]:
array(['20.57', '17.77', '132.9', '0.07017', '0.1812', '0.667'],
dtype='<U7')
The features array is fixed as U7; I can't change it to float; I can only make a new array with values derived from the original.