python - Building an array in a loop -


i writing python program imports 1000s of data point in blocks of 10 points @ time. each block of 10 data points maximum set found, program loops next 10 data points , continues. of works fine, need build array hold maximum data point created once per loop, can plot them later. how can create array within loop, here have:

for count in range(self.files/self.block_length):     rss = scipy.fromfile(self.hfile2, dtype=self.datatype, count=self.block_length)     maxrss = np.max(rss)#takes greatest value in array of size defined block_length 

here maxrss works great save file or print screen, program loops; however, @ end of loop holds last value , need hold of max values found

not sure if answer want... assuming for loop breaks 1000s of points correctly chunks of 10 (which don't see in example), create array within array, need make maxrss list , append things it:

maxrss = [] count in range(self.files/self.block_length):     rss = scipy.fromfile(self.hfile2, dtype=self.datatype, count=self.block_length)     maxrss.append(np.max(rss)) 

edit:

this not numpy, maybe help:

import random  data = [] _ in range(100):     data.append(random.randint(1, 100)) # ok, populated 100 integers.   # grab chunks of 10 "points" chunks=[data[x:x+10] x in xrange(0, len(data), 10)]  # initialization example done. now, max list: maxes = [] chunk in chunks:     maxes.append(max(chunk))     print "the max number in chunk %s was: %s" % (chunk, maxes[-1]) print maxes #prints out 10 max values of 10 arrays of 10 numbers 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -