I've defined a function that outputs two arrays [x] and [y]. My goal is to then call that function a number of times (in this example 10) and store each of those outputs into a different array so that I can average each array for x and y. I've started my code to call the function 10 times as follows: def myfunction() = myexamplefunction; in this function I've defined my output arrays x and y and can show that my function populates these values. For example, the x array looks like [[0, 1, 2, 1, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10] as an ouput.
Xtotal=[0] #new array that stores all the x values
Ytotal=[0] #new array that stores all the y values
for i in myfunction(range(10)):
Xtotal.append(x) #append the whole x array
Ytotal.append(y) #append the whole y array
alternately I've tried:
for i in range(10):
myfunction()
Xtotal.append(x) #append the whole x array
Ytotal.append(y) #append the whole y array
I've succeeded in calling my function 10 times but cannot get each output to nest in my new arrays. Any help would be appreciated. I'm learning python for this specific project so yes, I'm sure I'm missing some very basic things.
You must be sure that your function is returning the arrays at first e.g.:
def myfunction():
*
*
return X, Y # <-- this line
then you must call this function and puts its results in new variables i.e.:
Xtotal = []
Ytotal = []
for i in range(10):
x, y = myfunction() # <-- this line: put returned arrays X, Y in x, y
Xtotal.append(x) #append the whole x array
Ytotal.append(y) #append the whole y array