Run a function in another function N times

I have asked this question before, but it seems my previous question is a little misleading due to my poor English. Again, I ask you to clarify the situation. I am really confused. Thanks in advance.

Suppose I have a function A to create a cell state in a certain rule, and I have another function that generates a cell state for N times and every time the rule is the same as the fist function. And, yes, I don't know how to do it ...

def 1st_funtion(a_matrixA)
    #apply some rule on a_matrixA and return a new matrix(next state of the cell)
    return new_matrix

def 2nd_funtion(a_matrixB,repeat_times=n)
    #how to import the 1st_funtion and run for n times and return the final_matrix?
    #I know if n=1, just make final_matrix=1st_funtion(a_matrixB)
    return final_matrix

      

0


source to share


1 answer


def 1st_funtion(a_matrixA)
    #apply some rule on a_matrixA and return a new matrix(next state of the cell)
    return new_matrix

def 2nd_funtion(a_matrixB,repeat_times)

    for i in range(repeat_times):
        a_matrixB = 1st_funtion(a_matrixB)
    return a_matrixB

      



+2


source







All Articles