Looks like no one added any tags here yet for you.
How to use append?
# Create an empty list
my_list = []
# Append elements to the list
my_list.append(1)
my_list.append(2)
my_list.append(3)
print(my_list) # Output: [1, 2, 3]
How to stack two arrays of data into two columns?
time = np.array([1, 2, 3, 4, 5])
first_harmonic = np.array([0.5, 1.0, 1.5, 2.0, 2.5])
data_to_save = np.column_stack((time, first_harmonic))
How to save data to txt?
np.savetxt('file_name.txt', data_to_save, header='Time FirstHarmonic')
Reading data from txt
data = np.loadtxt(‘file_name’)
extracting data from rows of a loaded txt
time = data[:, 0] # first row
amplitude = data[:, 1] # second row
how to identify peaks in a 1D array?
peaks, _ = find_peaks(amplitude)
simple for loop
numbers = [1, 2, 3, 4, 5]
for n in numbers:
print(number)
for loops with range function
for i in range(5):
for j in range(i + 1):
print('*')
complex for loop to filter even number from a list
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] even_numbers = []
for num in numbers:
if num % 2 == 0:
even_numbers.append(num)
print("Even numbers:", even_numbers)
how does the return function work?
it returns a value determined my a function
def add(a, b):
result = a + b
return result
exponential function
def exponential_func(t, A0, d):
return A0 np.exp(-d t)
how to do a curve fit
popt, pcov = curve_fit(model_function, x_data, y_data)
take mean
mean = np.mean(data)
take standard deviation
sd = np.std(data)
how to dynamically name data files in a loop
for i in range(5):
file_name = f'data_{i}.txt'