I have the following code that does some calculation in a function depending on 2 variables (bh and frequency). when i run the code without loop with a fixed value of bh i get a proper output and data frame saved in a .csv file.:
bh frequency Re Im
0 1e-05 1 5.86848609615851 -0.999374346845734
1 1e-05 11 4.34298196390882 -0.994875549720418
2 1e-05 21 3.93236459069042 -0.99112086235206
3 1e-05 31 3.68545733552675 -0.987695572513367
4 1e-05 41 3.50849758486341 -0.984487932588323
however, i would like to loop on a list of bh values and frequency when i code in a loop on bh i get the same output as before meaning it doesn't loop. would anyone has a solution to amend the dataframe or save eaxh bh loop output in a new .csv in order to plot the data later on.
from mpmath import *
import numpy as np
import cmath
import math
import pandas as pd
mp.dps = 15; mp.pretty = True
a = mpf(0.25)
b = mpf(0.25)
z = mpf(0.75)
frequency = np.arange(1, 50, 10) # frequency range
bh = np.arange(10e-6, 30e-6, 10e-6) #10e-6 # width
print(bh)
D = 1e-6 #7.8e-4 # diffusivity
gamma = 0.5772 # Euler constant
v = []
w =[]
i = []
def q(frequency):
for i in bh:
# for f in frequency:
omega = (((i ** 2) * 2 * math.pi * frequency) / D) # depends on bh and frequency
u = ((-j/(math.pi * omega))*meijerg([[1, 3/2], []], [[1, 1], [0.5, 0]], j*omega))
v = np.real(u)
w = np.imag(u)
return i, frequency, v, w
#transpose arrays
T = np.vectorize(q)
print(T(frequency))
df = np.array(T(frequency)).T
print(df)
# create DataFrame
df1 = pd.DataFrame(data=df, columns=['bh', 'frequency','Re', 'Im'])
print(df1)
#save in .csv
df1.to_csv('C:\\Users\\calculations\\T.csv')