-1

I need a way to change an element of a string inside a for loop, in particular I have this:

N = 15
time_steps = np.linspace(0.005, 0.5, N)[:,None] 
for ii in time_steps:
   filter_results_file_name = 'augmented_filter_all_forces_ii.mat'

In particular I want that the string 'augmented_filter_all_forces_ii.mat' changes name in each iteration of the index ii, then for ii=0 I want 'augmented_filter_all_forces_0.mat', for ii=1 I want 'augmented_filter_all_forces_1.mat', and so on so forth.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61

1 Answers1

5

You could simply use an 'f-string' in python Something like:

for ii in time_steps:
   filter_results_file_name = f'augmented_filter_all_forces_{ii}.mat'
moritz
  • 92
  • 5