0

I know that one can generate an (arithmetic) progression with numpy like so:

>>> import numpy as np
>>> np.arange(10, 60, 10)
array([10, 20, 30, 40, 50])

So my question is can I call something that will do the reverse ?

E.g. :

>>> progression(np.array([10, 20, 30, 40, 50]))
(10, 60, 10)

This is most probably not trivial, but it would be nice if there's something in numpy/scipy that can do an approximation. Also bonus points if it can recognize the type of progression without specifying.

Note: I'm aware there are similar questions already asked, but this one specifically hasn't been answered, I think.

1 Answer 1

1

Since np.arange works with [start, end-step] with a step size. You can infer the parameters by hand:

def progression(x):
    step = x[1] - x[0]
    return x[0], x[-1] + step, step

This of course assumes the input array follows a sequential arangement!

Sign up to request clarification or add additional context in comments.

1 Comment

Correct, this will satisfy the example I gave. It won't work for anything else, however. Maybe I formulated it badly, but my question was more about advanced inputs, e.g. 1, 11, 2, 22, 3, 33 has a step of n,11*n. Closest I could find is the OEIS, but that's just a database. So I was wondering if there's something in numpy/scipy that can attempt to recognize progressions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.