Vectorization Of Multiple Return Of A Complex Function In A Dataframe
I am trying to plot various data including complex vectors.Thanks to contributors see answers https://stackoverflow.com/a/64480659/13953414, i managed to generate the dataframes bu
Solution 1:
np.vectorize
can return multiple "columns" as a tuple of arrays. Here I showcase how to add a "column" to the vectorized function and how to rearrange them.
def f_u(omega_elem):
val1 = (-j / (math.pi * omega_elem)) * meijerg([[1, 3 / 2], []], [[1, 1], [0.5, 0]], j * omega_elem)
asympt = (4 / (math.pi)) * (-(1 / 2) * np.log(omega_elem) + 3 / 2 - gamma - j * ((math.pi) / 4))
return val1, asympt
# return a tuple of array. Remember to assign two otypes.
f_u_vec = np.vectorize(f_u, otypes=[np.complex128, np.complex128])
tup = f_u_vec(omega) # tuple of arrays: (val1, asympt)
df["Re"] = np.real(tup[0]) # val1
df["Im"] = np.imag(tup[0])
df["asympt_R"] = np.real(tup[1]) # asympt
df["asympt_Im"] = np.imag(tup[1])
# result
df
Out[94]:
bh frequency Re Im asympt_R asympt_Im
0 0.00001 1 5.868486 -0.999374 5.868401 -1.0
1 0.00001 11 4.342982 -0.994876 4.341854 -1.0
2 0.00001 21 3.932365 -0.991121 3.930198 -1.0
3 0.00001 31 3.685457 -0.987696 3.682257 -1.0
4 0.00001 41 3.508498 -0.984488 3.504268 -1.0
5 0.00002 1 4.986257 -0.997867 4.985859 -1.0
6 0.00002 11 3.463849 -0.983559 3.459311 -1.0
7 0.00002 21 3.056269 -0.972212 3.047656 -1.0
8 0.00002 31 2.812349 -0.962168 2.799715 -1.0
9 0.00002 41 2.638332 -0.952979 2.621726 -1.0
Post a Comment for "Vectorization Of Multiple Return Of A Complex Function In A Dataframe"