Basically I am trying to avoid looping through big arrays before I had code that looked like this:
for rows in book:
bs = []
as = []
trdsa = []
trdsb = []
for ish in book:
var = (float(str(ish[0]).replace(':',"")) - float(str(book[0]).replace(':',"")))
if var < .1 and var > 0 :
bs.append(int(ish[4]))
as.append(int(ish[5]))
trdsa.append(int(ish[-2]))
trdsb.append(int(ish[-1]))
time = ish[0]
bflow = sum(numpy.diff(bs))
aflow = sum(numpy.diff(as))
OFI = bflow - aflow - sum(trdsb) + sum(trdsa)
OFIlist.append([time,bidflow,askflow,OFI])
I don't want to loop through the list twice as it consumes way too much time. I was thinking I could do a list comprehension but I'm not sure if I'm on the right track
OFIcreate(x,y):
bs = []
as = []
trdsa = []
trdsb = []
var = (float(str(y[0]).replace(':',"")) - float(str(x[0]).replace(':',"")))
if var < .1 and var >= 0 :
bs.append(int(ish[4]))
as.append(int(ish[5]))
trdsa.append(int(ish[-2]))
trdsb.append(int(ish[-1]))
time = ish[0]
bflow = sum(numpy.diff(bs))
aflow = sum(numpy.diff(as))
OFI = bflow - aflow - sum(trdsb) + sum(trdsa)
OFIlist.append([time,bidflow,askflow,OFI])
return OFIlist
OFIc = [ OFIcreate(x,y) for x in book for y in book)
The problem is that I want to loop through the list and group all instances where var >=0 and var <.1 then append values into a new list. The way I have it now I dont think it does that as it will just keep creating lists with a length of one. Any ideas on how I can accomplish this? Or rather how can I make the first block of code more efficient?
OFIcreate(x,y), soOFIcwill be just a list ofNone(s)