Jul-17-2019, 02:05 AM
(This post was last modified: Jul-17-2019, 02:05 AM by newatpython11.)
So i tried that and also moved diff out, but now it goes back to the original error i got. Now i have already converted the list to integer, since the original list is made of 50000 datapoints which have data with decimals. not sure what's going on!
%matplotlib inline import numpy as np import matplotlib.pyplot as plt from helper import plotHisto data = np.loadtxt('math_scores.txt') def myMap(inp, f) : res = [] for i in inp : res.append(f(i)) return res def new(x) : return int(x) pdata = myMap(data, new) def buildHisto(pdata, numbins, minimum, maximum) : histo = [] binwidth = diff/numbins for d in pdata : histo[d//binwidth]+=1 return histo minimum = min(pdata) maximum = max(pdata) diff = maximum - minimum histo = buildHisto(pdata, 10, minimum, maximum) plotHisto(histo, 'histo1.png', minimum, maximum, plotinline = True)
Error:---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-36-a1b9b926837f> in <module>()
26
27
---> 28 histo = buildHisto(pdata, 10, minimum, maximum)
29 plotHisto(histo, 'histo1.png', minimum, maximum, plotinline = True)
<ipython-input-36-a1b9b926837f> in buildHisto(pdata, numbins, minimum, maximum)
18 binwidth = diff/numbins
19 for d in pdata :
---> 20 histo[d//binwidth]+=1
21 return histo
22
TypeError: list indices must be integers or slices, not float