I have the following code:
result = np.zeros((samples,), dtype=[('time', '<f8'), ('data', '<f8', (datalen,))])
I would like to create variable tempresult that accumulates the data result, and once I have accumulated 25000 samples, I would like to perform some operation on it.
So I would like to do something like:
result = np.zeros((samples,), dtype=[('time', '<f8'), ('data', '<f8', (datalen,))])
tempresult.append(result)
if ( len(tempresult[0] > 25000 )):
# do something
I tried the answer code but I get exception TypeError: invalid type promotion
result = np.zeros((samples,), dtype=[('time', '<f8'), ('data', '<f8', (datalen,))])
if self.storeTimeStamp:
self.storeTimeStamp = False
self.timestamp = message.timestamp64
self.oldsamples = 0
for sample in range(0, samples):
sstep = self.timestamp + (self.oldsamples + sample) * step
result[sample] = (sstep, data[sample])
self.oldsamples = self.oldsamples + samples
# append
np.append(self.tempresult, result)
if len(self.tempresult) < 25000:
return
return [self.tempresult]
self.tempresult, thenlen(self.tempresult)is what is increasing each time you do so.len(self.tempresult[0])won't change (assuming that it's valid at all), andlen(self.tempresult[0] > 25000 )is just meaningless, you're asking for the length of a comparison result.np.appendwithout first reading and understanding its python code.