1/52
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
File System
Controls how data is stored and retrieved.
Path
the general form of the name of a file or directory, specifies a unique location in a file system.
How do you get your current working directory?
os.getcwd( ) or %pwd
How do you change your current working directory
os.chdir( )
"r"
Read - Default value. Opens a file for reading, error if the file does not exist.
"a"
Append - opens a file for appending, creates the file if it does not exist.
"w"
Write - opens a file for writing, creates the file if it does not exist.
"x"
Create - Creates the specified file, returns an error if the file exists.
How do you delete a file?
os.remove( )
NumPy
The core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays.
Arrays
a grid of values, all of the same type, and is indexed by a tuple of non-negative integers. The number of dimensions is the rank of the array; the shape of an array is a tuple of integers giving the size of an array along each dimension.
What are two ways to perform a matrix multiplication in two arrays?
Array1@Array2 or Array1.dot(Array2)
What does the axis define in an array?
axis = 0: columns , axis = 1: rows
What NumPy function converts degrees to radians?
np.deg2rad(degrees)
What would this code return in an array: (array[1:3, 1:4])
This will take the index of numbers from 1 to 4 from rows 1 and 2
What does the shape of an array mean and how do we check the shape of an array?
The shape of an array describes how many rows and columns in an array (rows, columns) and you can check the shape of an array with the function "array.shape"
How can you generate random numbers using the NumPy module?
np.random.randint
how can you transpose from rows to columns and vice versa?
vector_row.T (uppercase)
How can you get the cross product of two vectors?
(np.cross(v1, v2)
How can you find the determinant of an array?
det(x)
How can you find the identity matrix of an array?
np.identity(x.shape[0])
What is matplotlib.pyplot
a collection of functions allowing the creation of different graphs. Various states are preserved across function calls so that it keeps track of things like the current figure and plotting area.
Data models in matplotlib.pyplot
Has to be kept in sets which use curly brackets {'chocolate': 16, 'vanilla':13, 'strawberry':10}
What function creates a bar graph?
matplotlib.pyplot.bar
How can you modify the x-axis in a graph?
plt.xlabel(' ')
How can you make a scatter plot in matplotlib?
plt.scatter(' ')
How can you change the figure size in a graph?
plt.figure(figsize = (10,5))
How can you create two plots in one dataset?
plt.subplots( ) or (ax1,ax2) = plt.subplots(1,2)
Lambda function
a small, anonymous function defined using the lambda keyword. It can take any number of arguments but can only have one expression.
Bisection method
a method to find roots of a function f(x) within a given interval [a,b]. It works under the assumption that the function changes over the interval, meaning f(a) and f(b), the two initial guesses, must have opposite signs.
Requirements of the bisection method
- the function f(x) must be continuous within the given interval [a, b]
The function at the endpoints f(a) and f(b) must have _____ signs in the bisection method
opposite
Bisection method stopping criteria
The method stops when:
- the interval [a, b] becomes sufficiently small.
- the function value at the midpoint is close to zero.
- a maximum number of iterations in reached.
midpoint calculation
at each step, the midpoint c is calculated as c = a + b / 2
if f(a) * f(b) < 0
the root lies between a and c
if f(b) * f(c) < 0
the root lies between c and b
Bisection method (Convergence)
the method converges slowly but guarantees a root.
Secant method
a numerical method used for finding roots of a function. It approximates the derivative using values of the function at two points.
Secant method initial guesses
the secant method requires two initial guesses. However, unlike the bisection method, these guesses do not need to have opposite signs for their function values.
Secant formula
y = (f(b) - f(a)) / (b-a) * (x - a) + f(a)
Secant method stopping criteria
The method stops when:
- the difference between successive approximations is smaller than a tolerance value.
Secant method (convergence)
The method can converge faster than the bisection method, but it does not always guarantee convergence unless the initial guesses are close to the actual root.
SymPy
a python library for symbolic mathematics. Made to work with mathematical expressions symbolically rather than numerically, meaning it can perform algebraic manipulations and calculus operations.
Symbolic differentiation and integration with SymPy
refers to the process of computing the derivative function symbolically, providing an exact expression for the rate of change of the function.
Numerical differentiation
refers to the methods for estimating the derivative of a function based on discrete data points. Unlike symbolic differentiation, numerical differentiation uses approximation techniques to estimate derivates when you don't have the symbolic expression but only numerical data of a function at specific points.
Forward difference for numerical differentiation
a method used to approximate the derivative of a function using numerical techniques. This method is particularly used when you don't have the explicit derivative of a function but need to estimate it based on discrete points or numerical data.
Forward difference (Key points)
Step size- the step size (h) should be small to improve accuracy, but if it's too small, it can introduce numerical errors due to limited precision in floating point calculations.
One - sided approximation- unlike other methods, the forward difference only looks at values ahead of (x) which makes it less accurate but easy to compute in some situations.
Applications- this method is useful in scenarios where you have a function represented by discrete data points or when computing derivatives symbolically is difficult.
Backward difference for numerical differentiation
a numerical method used to approximate the derivative of a function. This method is especially useful when you have discrete data points and need to estimate the derivative at a specific point.
backward difference formula
f'(x) = f(x) - f(x - h) / h
Backward difference concept
In this method, we estimate the slope of a tangent to the curve at point (x) by calculating the slope of the line between (x) and a nearby point (x - h). The smaller the value of (h) the close the line between (x) and (x - h) will be to the actual tangent, improving the accuracy of the approximation.
Backward difference (key points)
Step size (h)- the step size should be small to enhance accuracy. However, if it is too small it can cause numerical errors.
One - sided approximation- unlike other methods, the backward difference only uses data points behind (x), which makes it straightforward to compute but potentially less accurate.
Applications- this method is useful when dealing with time series data or when the function values are known only at discrete points and you need to estimate the derivative using past values.
Numerical Integration
refers to techniques used to approximate the integral of a function when an exact analytical solution is difficult or impossible to obtain. It involves using numerical methods to estimate the value of definite integrals.
Trapezoid method for numerical integration
a numerical technique used to approximate the definite integral of a function. It works by approximating the area under the curve as a series of trapezoids, rather than as a series of rectangles.