Skip to content
Advertisement

Numpy applying a time interval sequence to a multidimensional ndarray (such as coordinates)

EDIT: added prefix / suffix value to interval arrays to make them the same length as their corresponding data arrays, as per @user1319128 ‘s suggestion and indeed interp does the job. For sure his solution was workable and good. I just couldn’t see it because I was tired and stupid.

I am sure this is a fairly mundane application, but so I have failed to find or come up with a way to do this without doing it outside of numpy. Maybe my brain just needs a rest, anyway here is the problem with example and solution requirements.

So I have to arrays with different lengths and I want to apply common time intervals between them to these arrays, so that that the result is I have versions of these arrays that are all the same length and their values relate to each other at the same row (if that makes sense). In the example below I have named this functionality “apply_timeintervals_to_array”. The example code:

JavaScript

So one could then use the common arrays for additional computations or for rendering.

The question is what could accomplish the “apply_timeintervals_to_array” functionality, or alternatively a better way to generate the same data.

I hope this is clear enough, let me know if it isn’t. Thank you in advance.

Advertisement

Answer

I think , numpy.interp should meet your expectations.For example, If a have an 2d array of length 20 , and would like to interpolate at different common_ti values ,whose length is 30 , the code would be as follows.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement