Shared Flashcard Set

Details

Topic Sections 1-12
University Of Cambridge Engineering Undergraduate Course Flashcards
17
Engineering
Undergraduate 1
12/22/2024

Additional Engineering Flashcards

 


 

Cards

Term
Complex Data type creation
Definition
Complex number: "a = b + cj"
Term
How to cut up a string or array
Definition
String:
"s = my_string[0:6]" is first 6 letters of my_string.

Array:
"A = my_array[0:6]" is first 6 items of the array.
2d Array:
Regular - "name = lab_groups[1][2]" is row 2 column 3.
numpy - "name = lab_groups[1,2]"
Term
Type conversions
Definition
"float(a)"
"int(a)"
"str(a)"
Term
What libraries are useful?
Definition
math, random, numpy
"help(LibraryName)" lists out all the functions imported.
Term
How do you import just a function from a library?
Definition
"from math import sqrt as Some_Function"
Term
How do you format a string?
Definition
"print(f"My name is {name} and I'm {age} years old.")"
Term
Lists and nested lists
Definition
lab_group0 = [8,9]
lab_group1 = [1,2,3]

nested_lab_groups = [lab_group0, lab_group1]
nested_lab_groups == [[8,9],[1,2,3]]

"list = [0]*5" makes a list of 5 zeros.
"list.append()"
Term
Tuples
Definition
A list that cannot be changed after creation.
"t = ("str", 0)"

By doing "t = ("str",)" the len(t) = 1, instead of three (length of "str").
You can make a list of tuples.
Term
Dictionaries
Definition
"rooms = {"Joe": None, "Bob": 32, "John": 31}"
"Bob_room = rooms["Bob"]"
Therefore, Bob_room == 32

""Jess" in rooms" is false
""Joe" in rooms" is true
Term
Numpy
Definition
"x = np.zeros(5)"
"y = np.random.rand(6)"
"z = np.array([2,3,4])"
"a = np.arrange(6)":
Equally spaced values, [0 1 2 3 4 5] for this one.

"b = np.linspace(0,100,6)":
(start val, end val, number of items), [ 0. 20. 40. 60. 80. 100.].
Start/End val are inclusive.

"c = 10.0*a" scales all values in x by 10.
Term
%time norm
Definition
%time norm = f(x) calculates the time to complete function f upon x.
Term
2D Arrays
Definition
"A = np.array([[2, 3, 9.1], [3, 1.3, 1]])"
"A.shape" is (2,3) <-- tuple
Term
Matrix multiplication
Definition
"y = A.dot(x)" is 'y = Ax'

"Ainv = np.linalg.inv(A)"
"Adet = np.linalg.det(A)" are both useful.
Term
Plotting graphs
Definition
"import matplotlib
import matplotlib.pyplot as plt"

"plt.plot(x, f)" plots two arrays against each other.
"plt.loglog()" creates a log graph;.

"plt.xlabel('$x$')
plt.ylabel('$f$')
plt.title("Simple plot of $x$ vs $f$")"

"plt.xlim(x[0], x[-1])" limits the graph size.

"plt.show()" displays the graph.
Term
Error handling
Definition
"raise ErrorType("Error message")"

"Try:
Except:"
Term
Algorithms
Definition
Binary search: Find the midpoint and work from there.

Bubble sort:Iterate across the array and if any neighbours are in the wrong place they are swapped.

Quick sort: a pivot point is chose at the mid point of remaining arrays and larger/smaller values are seperated.
Term
Object Oriented
Definition
[image]
[image]
Supporting users have an ad free experience!