Q:

How to recognize which mathematical function generated a curve given by X and Y arrays in sympy

How can I get the mathematical function from numerical values of X and Y array using sympy or however else in Python?
Just to be clear:
For following X and Y:
X = [0, 1, 2, 3, 4, 5]
Y = [2, 2, 2, 2, 2, 2]

I'd like to say that it is f(x) = kx+l, and with k and l if possible.
I have to find inverse of a function for which I only know a shape. It can be a fit, doesn't have to be 100% exact.

A:

You appear to potentially be looking for the interpolate function from sympy.polys.polyfuncs, which can construct an interpolating polynomial for your data points. Note that this only does polynomial interpolation, it isn't some general equation-solver, which would be far more difficult.  Your given example is rather basic as your f(x) would just be 2 with k = 0 and l = 2, but for a more general example you may have 
from sympy.polys.polyfuncs import interpolate
from sympy.abc import x
a = [1, 2, 3]
b = [3, 5, 7]
data = list(zip(a,b))
print(interpolate(data,x))

Outputs:
2*x + 1

You can extract the coefficients from your polynomial with Poly.coeffs afterwards
result = sympy.polys.polyfuncs.interpolate(data,x)
coefficients = sympy.Poly(result).coeffs()
print(coefficients)

Outputs:
[2,1]

