I need to make ‘n’ copies of this code:
ccfarray1=[]
def ccf1(binnum):
for i in datarange:
ccf=((a[i]-xbar)*(c[(i-binnum)]-ybar))/(norm*stdevx*stdevy)
parray.append(ccf)
calc=sum(parray)
ccfarray1.append(calc)
del parray[:]
return ccfarray1
so that for example one copy of it is is:
ccfarray2=[]
def ccf2(binnum):
for i in datarange:
ccf=((a[i]-xbar)*(c[(i-binnum)]-ybar))/(norm*stdevx*stdevy)
parray.append(ccf)
calc=sum(parray)
ccfarray2.append(calc)
del parray[:]
return ccfarray2
Whereby each time a new array is made, ccfarray’n’.
I need this like 20 times, but that’s a lot of copying and pasting. Is there an elegant solution to code this and if I need to change the number of times I need it.
I need a lot of these because I’m treating them as bins. If ‘binnum’ falls between a certain range, then I need it to be appended to a different array than if binnum fell between a different range.
If there is code that can do this without so much code than thats fine, but I don’t know how to do that!
I am not completely sure what you want to do with your functions but you can create functions inside closure, and than put them as items to some list, like this:
So, if you want 20 functions you just create them like this:
and than call them like this: