0

An array in python is a function of integers, namely arr[0],arr[1],arr[2]. Does there exist a function to represent array values as a continuous function?

tesgoe
  • 1,012
  • 3
  • 10
  • 19
  • 1
    you may want to write a function for interpolation. http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.interp.html – ssm May 23 '16 at 09:26
  • Please, made an example of use. – pbacterio May 23 '16 at 09:48
  • @ssm And if I have two arrays, namely x(t) and y(t), how do I get y(x), for which I can then use scipy.interp? – tesgoe May 23 '16 at 09:50
  • @pbacterio Higher resolution via interpolation helps to solve arbitrary problems that need this higher resolution. – tesgoe May 23 '16 at 09:52
  • @tesgoe For finding y(x) given x(t) and y(t): short answer - for the general case, you cannot. Why? Because, for that to be possible, you will need x(t) to be reversible. i.e. either monotonically increasing, or monotonically decreasing, so that you can find the inverse function t = x_inv(x), and y(x_inv(x)). However, if x(t_1) = x(t_2) = x0, then, will you compute y(t_1) or y(t_2)? – ssm May 23 '16 at 14:31

1 Answers1

1

there is a linear interpolation.

class continuousFun(object):
    def __init__(self,initialArray):
        self.initialArray = initialArray
        self.delta=[]
        for index in range(len(self.initialArray)):
            if index==0:self.delta.append(self.initialArray[index]-0)
            else:self.delta.append(self.initialArray[index]-self.initialArray[index-1])
    def getValue(self,pseudoIndex):
        return self.initialArray[int(pseudoIndex)]+self.delta[int(pseudoIndex)+1]*(pseudoIndex-int(pseudoIndex))

array=continuousFun([0,4,9,2,4,5,9,10])

print array.getValue(0.5)
user5698387
  • 477
  • 3
  • 10