I have numpy array and I want to use power series like taylor series of e^x
, and I am wondering how to implement this in python. For the simplicity purpose, I think I can use maclaurin series at x0=0
, wheres x
is numpy array. Basically, I have 1 dim pixel vector, and I want to non-linearly expand each pixel value by using taylor series expansion of e^x. In other words, in output vector, each pixel will be replaced with first and second term of taylor series expansion term. Any idea to make this happen in python?
mathematical concept:
here is the simple math concept I want to accomplish, wheres nunmpy array is expected to be non-linearly expanded by using power series like maclaurin series of e^x
.
my attempt:
import numpy as np
arr= np.array([[120.0,24.0,12.0],[14.0,28.0,43.0]])
arr= arr/255.0
def maclurin_exp(x, power):
res = x*0
for i in range(power):
res += x**i/math.factorial(i)
return res
## test my code:
maclurin_exp(x=arr, power=3)
new update 2:
Precisely, F
is taylor series of e^x
, x
is each pixel value, x0
is approximation point at 0. For example if we have 8 pixel in 1 dim vector, then after we used taylor series of e^x for each pixel value, first and second term of taylor expansion will be considered as ouput.
how do I make this happen in python? any workaround to accomplish the implementation of Maclaurin series for e^x
in more compact way? any thought?
expected output
for example we have 1 dim pixel vector [1,2,3,4,5,6,7,8]
, then we apply above mathematical equation to approximate each pixel value by using maclurin series of e^x:
pixel = [1,2,3,4,5,6,7,8]
then first and second term of taylor series of e^x for each pixel value would be my final output.