I have the following code with the given arrays a
and b
.
import numpy as np
# Parts of interest are highlighted with ^ ...
a = np.array([0,2,9,12,18,19])
# ^^ ^^
b = np.array([1,1,1,2,1,3]
# ^ ^
# Should result in an array like
assert result == np.array([0,2,9,12,13,18,19,20,21])
# ^^ ^^ ^^ ^^ ^^
The values in b
define how many increments of the value in a
(at the same index) should be inserted in the result. Ones in b
don't affect the result. I think that I could do some splitting/joining and use a loop. But I'm wondering if this can be solved with numpy functions and good performance?
Thank you for your help!