[Tutor] whats the best way to structure my data?

Jeff Peery jeffpeery at yahoo.com
Fri May 11 01:28:46 CEST 2007

hello, I was wondering what might be the best way to structure my data within python. I am sampling data points, and in each there is a time, value, and text string associated with that sample. so I was thinking I'd make a list of 'measurement objects' and each object would have the attributes: time, value, and text... but I want to operate on the numerical values to find the average and stdev... so I'm not sure how to operate on my data if it is inside an object.

right now I have three arrays, a date array, a value array, and a text array. so I can operate on each array without trouble. but it'd be cleaner in my code and easier to deal with if I had a list of these measurement objects.

for example:

# a class for my measurements
class measurement:
    def __init__(self):
        self.text = ''

# I start with an empty list
measurements = []

# as I collect data in my code I append an object to the list
measurements[-1].value = value
measurements[-1].text = text
measurements[-1].time = time

# now I don't know what to do here. I want the mean of all my data
# but I need a list or array to operate on but instead my data is inside each object
# I don't really want to make a temporary array, is there a way to operate on the
# data in all my objects as if it were an array or list?

mean = numpy.mean(????)

is there a way to operate on the data when it is structured like this?


Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070510/950fff79/attachment.htm 

More information about the Tutor mailing list