Like many others, my situation is that I have a class which collects a large amount of data, and provides a method to return the data as a numpy array. (Additional data can con
I will use array.array()
to do the data collection:
import array
a = array.array("d")
for i in xrange(100):
a.append(i*2)
Every time when you want to do some calculation with the collected data, convert it to numpy.ndarray
by numpy.frombuffer
:
b = np.frombuffer(a, dtype=float)
print np.mean(b)
b
will share data memory with a
, so the convertion is very fast.