Skip to content
Advertisement

Add in-between steps into array of numbers (Python)

I am looking for some function that takes an input array of numbers and adds steps (range) between these numbers. I need to specify the length of the output’s array.

Example:

JavaScript

Result:

JavaScript

Is there something like that, in Numpy for example?

I have a prototype of this function that uses dividing input array into pairs ([0,2], [2,5], [5,8]) and filling “spaces” between with np.linspace() but it don’t work well: https://onecompiler.com/python/3xwcy3y7d

JavaScript

How it works:

JavaScript

I have an array [1, 2, 5, 4] and I need to “expand” a number of items in it but preserve the “shape”:

enter image description here

Advertisement

Answer

There is numpy.interp which might be what you are looking for.

JavaScript

output:

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