ThePortakal
ThePortakal

Reputation: 239

Resample a categorical numpy array

I have a 1 dimensional numpy array labels (say its length is 700k) sampled at 700 Hz. So, it corresponds to 1000 seconds of time series data. The array consists of integers 0 to 3 which stand for some categorical information. Also, the categories rarely change, like 200 seconds of 0, then 150 seconds of 2 and so on...

Now, I would like to convert it to an array of 64 Hz, that is, the new length of the array will be 700k x (64/700) = 64k.

resampledLabels = scipy.signal.resample(labels, 64000)

The problem with the above code is that it makes some assumptions about the array, and make interpolations. I tried to round them to the nearest integer, but the result also contained a -1 which is actually out of the range of the actual array.

My problem is, how can I resample the array without making interpolations?

Upvotes: 0

Views: 209

Answers (1)

Ralvi Isufaj
Ralvi Isufaj

Reputation: 482

I think you can just simple numpy slicing, which is of the format start:stop:step. This is constant time and reflects possible changes you might make to the resampled array. In your case it would be: labels[0::64000]

Upvotes: 1

Related Questions