I have a fully functional code with three functions each of which returns outputs of it own. My task is to create one function which can call all the other functions and return the outputs of all the functions. how do I do that? My code is as follows:
def func(x, y):
return x * x + y * y, x * y
def generate_data(size):
nx = 5
mx = 0.5
mux, sigmax = nx, mx/3
ny = 3
my = 0.9
muy, sigmay = ny, my/3
result1=[]
result2=[]
for i in range(size):
result = func(random.gauss(mux, sigmax), random.gauss(muy, sigmay))
result1.append(result[0])
result2.append(result[1])
return result1, result2
def analysis(ls):
avg = np.mean(ls)
std = np.std(ls)
pre = 3 * std
return avg, std, pre
say, for eg: I need to create a function
def My_func()
and this function should have the other functions and returns its outputs
Just as you have done in each of your existing functions, you can return multiple results in one line.
def My_func(x, y, size, ls):
return analysis(ls), generate_data(size), func(x,y)
You can return them at once.Like this:
return analysis(x,y), generate_data(size), func(ls)
To receive the value, you have to unpack
Valanalysis,Valgenerate_data,valfunc=My_func(x, y,size,ls)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.