python - Time-varying data: list of tuples vs 2D array? -


my example code in python i'm asking general principle.

if have set of data in time-value pairs, should store these 2d array or list of tuples? instance, if have data:

v=[1,4,4,4,23,4] t=[1,2,3,4,5,6] 

is better store this:

data=[v,t] 

or list of tuples:

data=[(1,1),(4,2)(4,3)...] 

is there "standard" way of doing this?

the aggregate array container best choice. assuming time points not regularly spaced (and therefore need keep track of rather use indexing), allows take slices of entire data set like:

import numpy np v=[1,4,4,4,23,4] t=[1,2,3,4,5,6]  data = np.array([v,t]) 

then slice subset of data easily:

data[:,2:4]  #array([[4, 4],[3, 4]])  ii = [1,2,5] # fancy indexing data[:,ii] # array([[4, 4, 4],            #        [2, 3, 6]]) 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -