Premium problem144. Month-over-Month Growth Rate

Easy Locked

Given a 1-D float array of monthly revenue in chronological order, return an array of the same length:

  • element 0 is np.nan
  • element i is (x[i] - x[i-1]) / x[i-1]
  • a zero prior month yields np.nan

Input

[100. 110.  99.   0.  50.]

Output

[ nan  0.1 -0.1 -1.   nan]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)