Comp Lab Python

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:26 AM on 4/7/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

15 Terms

1
New cards

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]

2
New cards

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

3
New cards

How to save data to txt?

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

4
New cards

Reading data from txt

data = np.loadtxt(‘file_name’)

5
New cards

extracting data from rows of a loaded txt

time = data[:, 0] # first row

amplitude = data[:, 1] # second row

6
New cards

how to identify peaks in a 1D array?

peaks, _ = find_peaks(amplitude)

7
New cards

simple for loop

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

for n in numbers:
print(number)

8
New cards

for loops with range function

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

9
New cards

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)

10
New cards

how does the return function work?

it returns a value determined my a function

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

11
New cards

exponential function

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

12
New cards

how to do a curve fit

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

13
New cards

take mean

mean = np.mean(data)

14
New cards

take standard deviation

sd = np.std(data)

15
New cards

how to dynamically name data files in a loop

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

Explore top flashcards

flashcards
APUSH Progressive Era PEDLIGS
84
Updated 907d ago
0.0(0)
flashcards
US History Chapter 10 Test
32
Updated 98d ago
0.0(0)
flashcards
Latin and Greek Roots List 1-3
75
Updated 333d ago
0.0(0)
flashcards
Numbers 1 - 20
20
Updated 528d ago
0.0(0)
flashcards
Business Law - Midterm
126
Updated 186d ago
0.0(0)
flashcards
La inmigración
45
Updated 488d ago
0.0(0)
flashcards
APUSH Progressive Era PEDLIGS
84
Updated 907d ago
0.0(0)
flashcards
US History Chapter 10 Test
32
Updated 98d ago
0.0(0)
flashcards
Latin and Greek Roots List 1-3
75
Updated 333d ago
0.0(0)
flashcards
Numbers 1 - 20
20
Updated 528d ago
0.0(0)
flashcards
Business Law - Midterm
126
Updated 186d ago
0.0(0)
flashcards
La inmigración
45
Updated 488d ago
0.0(0)