I have a file with headers containing ‘#’ then the data which is comma separated. i.e
#blah
#blah
#blah
1, 2, 3, 4, 5, 6
7, 8, 9,10,11,12
...
I want to be able to skip the # and turn the data into an array (histograms over the columns). This reads it in.
filename = 'input.txt'
listin = []
for line in open(filename,'r'):
li=line.strip()
if not li.startswith("#"):
line = line.partition('#')[0]
#line = line.rstrip()
listin.append(line.split(','))
data = numpy.asarray(listin)
SubData=data[:,0]
hist,nbins = np.histogram(SubData)
Error:
TypeError: cannot perform reduce with flexible type
You need to convert your data to a numeric type. Your array contains strings.
Also, you need to rstrip each line to remove the line break character.