def sort_array(arg0,arg1=None,decimate=True,as_index=False):
"""
Args can be an (N,2) array or a tuple with 2 (times,values) arrays
Takes two arrays of times and values of the same length and sorts the (time,value)
The decimate argument just removes repeated timestamps, not values
"""
import numpy as np
t0=time.time()
#times = np.random.random_integers(N,size=(N,))
#values = np.random.random_integers(3000,4000,size=(N,))
data = arg0 if arg1 is None else (arg0,arg1)
if len(data)==2:
times,values = data
data = np.array((times,values)).T #Build a new array for sorting
#Sort the array by row index (much faster than numpy.sort(order))
time_index = get_col(np.argsort(data,0),0)
if as_index:
if not decimate:
return index
else:
return np.compress(get_array_steps(get_col(data,0).take(time_index)),time_index,0)
else:
sdata = data.take(time_index,0)
if decimate:
sdata = np.compress(get_array_steps(get_col(sdata,0)),sdata,0)
print time.time()-t0
return sdata
评论列表
文章目录