python - Circular buffer of vectors -


i getting float stdin once persecond , processing it. however, need handle several space-separated values each second instead. inexperienced python, hard select suitable data structure.

  • i need compute mean of data per channel. if data stored numpy.matrix, straightforward.

  • i need store fixed number of points of history per channel. now, collections.deque(maxlen=x) doing quite nicely.

  • lastly, need pass iterables y_axis in matplotlib.axes.plot(x_axis, y_asis) many times needed draw signals. example, if data stored deque of matrices, each second need compose lists of values each channel.

what data structure shall use?

your process seems slow, have time info in deque. , integrate numpy world ease of mean , plot. can :

10 buffers

run main() animation.

import numpy np import matplotlib.pyplot plt import collections co buffer=[] in range(10):     buffer.append(co.deque(maxlen=15))  def refresh(n):     t in range(10*n):         x=np.random.rand()+t%10         buffer[t%10].append(x)  refresh(15) # init   buff=np.asarray(buffer) fig = plt.figure() ax = fig.add_subplot(111) line = ax.plot(buff.t)    def main():     while true:         refresh(1)         buff=np.asarray(buffer)          print (buff.mean(axis=1))         in range(10) :             line[i].set_ydata(buff[i])         fig.canvas.draw()         t in range(10**6):pass #tempo 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -