I have a function that produces an array within it, and I want to do work on the generated array outside of the function, in python. How can I make the function save the array such that this can be done?
Thanks!
My function is here:
def lane_emden(n, delxi=0.00001, xilim=25):
theta = 1
dtdx = 0
xi = 0.01
#Starting values
dtdx_values = [dtdx]
theta_values = [theta]
xi_values = [xi]
#Initial values for the lists
while theta>=0 and xi<=xilim :
dtdx_new = dtdx - ((2*(2/xi*dtdx)) + theta**n)*delxi
theta_new = theta + delxi*dtdx_new
xi_new = xi + delxi
#Equations to create new values for iterative diff eq solving
dtdx = dtdx_new
theta = theta_new
xi = xi_new
#Replace the old values with the new ones
dtdx_values.append(dtdx)
theta_values.append(theta)
xi_values.append(xi)
#Store these new values in previously defined lists
results = np.array((theta_values, xi_values))
#create an array of the results (probably done incorrectly)
return results
#This is how I tried to get the array saved outside the function
I'm very new to Python, any help would be greatly appreciated!
[Edit] Function call as requested.
Input
lane_emden(5)
Output
array([[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, ...,
2.10576105e-01, 2.10576063e-01, 2.10576022e-01],
[ 1.00000000e-02, 1.00100000e-02, 1.00200000e-02, ...,
2.49999900e+01, 2.50000000e+01, 2.50000100e+01]])