I have a list
X
containg the data performed by different users N
so the the number of the user is i=0,1,....,N-1
. Each entry Xi
has a different length.
I want to normalize the value of each user Xi
over the global dataset X
.
This is what I am doing. First of all I create a 1D
list containing all the data, so:
tmp = list()
for i in range(0,len(X)):
tmp.extend(X[i])
then I convert it to an array and I remove outliers and NaN
.
A = np.array(tmp)
A = A[~np.isnan(A)] #remove NaN
tr = np.percentile(A,95)
A = A[A < tr] #remove outliers
and then I create the histogram of this dataset
p, x = np.histogram(A, bins=10) # bin it into n = N/10 bins
finally I normalize the value of each users over the histogram I created, so:
Xn = list()
for i in range(0,len(X)):
tmp = np.array(X[i])
tmp = tmp[tmp < tr]
tmp = np.histogram(tmp, x)
Xn.append(append(tmp[0]/sum(tmp[0]))
My data set is very large and this process could take a while. I am wondering if there is e a better way to do that or a package.
for i in range...
so that's where I would focus on optimizing. Have you considered usingpandas
? If you can provide a sample of the input data, yourlist X
then it will be easier to make a recommendation that will give you the desired output that would take less time. Are you trying to get the histogram so that you can graph it? \$\endgroup\$