Comp Lab Python

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 14

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

15 Terms

1

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]

New cards
2

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))

New cards
3

How to save data to txt?

np.savetxt('file_name.txt', data_to_save, header='Time FirstHarmonic')

New cards
4

Reading data from txt

data = np.loadtxt(‘file_name’)

New cards
5

extracting data from rows of a loaded txt

time = data[:, 0] # first row

amplitude = data[:, 1] # second row

New cards
6

how to identify peaks in a 1D array?

peaks, _ = find_peaks(amplitude)

New cards
7

simple for loop

numbers = [1, 2, 3, 4, 5]

for n in numbers:
print(number)

New cards
8

for loops with range function

for i in range(5):
for j in range(i + 1):
print('*')

New cards
9

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)

New cards
10

how does the return function work?

it returns a value determined my a function

def add(a, b):
result = a + b
return result

New cards
11

exponential function

def exponential_func(t, A0, d):
return A0 np.exp(-d t)

New cards
12

how to do a curve fit

popt, pcov = curve_fit(model_function, x_data, y_data)

New cards
13

take mean

mean = np.mean(data)

New cards
14

take standard deviation

sd = np.std(data)

New cards
15

how to dynamically name data files in a loop

for i in range(5):
file_name = f'data_{i}.txt'

New cards
robot