I am trying to find a min value from one dimensional numpy array which which looks like:
col = array(['6.7', '0.9', '1.3', '4', '1.8'],dtype='|S7'),
using col.min(), which is not working.
I tried as suggested on NumPy: get min/max from record array of numeric values view function, it failed to recognize ‘S7’ as valid field.
What is the best way to deal with this problem? Should I have specified the data type while reading the values or while using the min function?
The problem is that you have an array of strings, not an array of numbers. You therefore need to convert the array to an appropriate type first:
If you know the input to be numeric, it would make sense to specify the data type when reading the data.