Before the for loop I initialized my matrix with zeros: falff = np.zeros(data_matrix.shape[0]) and inside the for loop I did not add any line besides the 2 posted earlier. Data matrix is what I am passing as an argument to my compute_falff function along with low pass, high pass and TR, so it would depend on how you have defined your data.