Chapter 12 Flashcards
What is a docstring?
A comment at the start of every function
What is a package?
A group of modules
How do you access a function from a module?
module_name.function_name(arguments)
How do you import a specific function instead of a whole module?
from <module_name> import <function_name></function_name></module_name>
How do you rename a module
import <module_name> as <new_name>
e.g.
- from math import sqrt as sr</new_name></module_name>
What is a vector?
An array of elements of one direction,
- can be up or down
What are he two types of vectors?
- Row
- Column
Can you add vectors or matrices together?
If they have the same dimensions yes
What does multiplying a matrix by a scalar constant do?
Multiplies all values in a matrix by the scalar value
How does matrix subtraction work?
Parallel values subtract,
- 2nd value is subtracted from 2nd value
What is the noation for a column vector?
[n,0]
N rows, one column
What is notation for a row vector?
[0,n]
one down, n wide
What is a diagonal matrix?
A square matrix where all values = 0 besides the diagonal values where m = n
a_mn
What is a triangular matrix
A matric where one side of the square matrix is 0 and the rest has values, split diagonally into a triangle
What is a tridiagonal matrix?
When the square matrix has 3 diagonals with values, the rest is zero
What is a transpose matrix?
When a matrix (m x n) changes to (n x m)
What happens when you transpose a row vector?
You get a column vector because m and n are getting swapped
Is matrix division possbile?
Yes
A / B = A / B^-1
I think check this out
Does matrix A x matrix B = matrix B x matrix A?
No
How do you divide two matrixes?
What is a module?
A file containing code that can be imported and used in other modules or scripts
When importing a module how do you access variables within that module?
dot notation,
module_name.varibale
e.g
names.py:
first = ‘Larry’
last = ‘David’
write_names.py:
import names
print(names.first, names.last)
What is a script?
A file containing python code that is passed as an input to the interpreter
What is the console used for?
Coding line by line and receiving an output each time,
- typically used for very short codes or to test syntax
What is dot notation?
module.object
What does python use to determine whether the program is executed as a script or as an imported module?
execute code as script
if __name__ == ‘__main__’:
#indented code
# run as script
What happens when a module is imported and called for in a script?
The modules code is run
What file extension must a module have in order to be imported?
.py
Are module imports case sensitive?
Yes
What is it called when a program requires a module to run?
dependency
What happens when you import a module into python?
The interpreter evaluates it immediately
- Checks if it has already been imported
- if it has, use the currently loaded module
- If not, create a new module object for the module
What is a module object?
A namespace that contains definitions from a module
How do you change the value of an object in a module?
module.object() = value
What happens after you change the value of an object in a module?
the module is reloaded with new values, though when another program imports the module, all objects are back to normal
When importing a module, the interpreter first looks for____?
An built-in module, if there is no match, then python looks in sys.path
What are the three initial directories that are contained in sys.path?
- The directory of the executing script
- A list of directories specified by the environment variable PYTHONPATH (this variable can be set in the OS)
- The directory where python is installed