I have a file text with data in a following format:
rubbish & 3.97& 3.83& 3.95& 3.83& 3.82
rubbish & 4.92& 4.81& 4.88& 4.81& 4.81
rubbish & 5.90& 5.66& 5.88& 5.66& 5.66
rubbish &--- & 6.05& 6.14& 6.05& 6.05
rubbish & 6.42& 6.26& 6.46& 6.26& 6.26
rubbish &--- & 6.56& 6.63& 6.56& 6.56
And I want to read them into numpy.ndarray object so that numbers are transformed into floating point number object while the ---
stay as the string objects. However, the following piece of code creates an expected numpy.array object but everything in there is a string.
import numpy as np
wejscie = open('data.dat', 'r').readlines()
def fun1(x):
print x
if x.strip() == '---':
return str(x)
else:
return float(x)
dane = np.array([map(fun1, linijka.split('&')[1:]) for linijka in wejscie])
So is it possible to have numpy.ndarray object containing data of various types?