Chapter 12 Flashcards

1
Q

What is a docstring?

A

A comment at the start of every function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a package?

A

A group of modules

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you access a function from a module?

A

module_name.function_name(arguments)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you import a specific function instead of a whole module?

A

from <module_name> import <function_name></function_name></module_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you rename a module

A

import <module_name> as <new_name>
e.g.
- from math import sqrt as sr</new_name></module_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a vector?

A

An array of elements of one direction,
- can be up or down

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are he two types of vectors?

A
  • Row
  • Column
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can you add vectors or matrices together?

A

If they have the same dimensions yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does multiplying a matrix by a scalar constant do?

A

Multiplies all values in a matrix by the scalar value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does matrix subtraction work?

A

Parallel values subtract,
- 2nd value is subtracted from 2nd value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the noation for a column vector?

A

[n,0]
N rows, one column

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is notation for a row vector?

A

[0,n]
one down, n wide

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a diagonal matrix?

A

A square matrix where all values = 0 besides the diagonal values where m = n
a_mn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a triangular matrix

A

A matric where one side of the square matrix is 0 and the rest has values, split diagonally into a triangle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a tridiagonal matrix?

A

When the square matrix has 3 diagonals with values, the rest is zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a transpose matrix?

A

When a matrix (m x n) changes to (n x m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What happens when you transpose a row vector?

A

You get a column vector because m and n are getting swapped

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Is matrix division possbile?

A

Yes
A / B = A / B^-1
I think check this out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Does matrix A x matrix B = matrix B x matrix A?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you divide two matrixes?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a module?

A

A file containing code that can be imported and used in other modules or scripts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

When importing a module how do you access variables within that module?

A

dot notation,
module_name.varibale

e.g
names.py:
first = ‘Larry’
last = ‘David’

write_names.py:
import names
print(names.first, names.last)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a script?

A

A file containing python code that is passed as an input to the interpreter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the console used for?

A

Coding line by line and receiving an output each time,
- typically used for very short codes or to test syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is dot notation?
module.object
26
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 #code not indented in if is run as an imported module
27
What happens when a module is imported and called for in a script?
The modules code is run
28
What file extension must a module have in order to be imported?
.py
29
Are module imports case sensitive?
Yes
30
What is it called when a program requires a module to run?
dependency
31
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
32
What is a module object?
A namespace that contains definitions from a module
33
How do you change the value of an object in a module?
module.object() = value
34
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
35
When importing a module, the interpreter first looks for____?
An built-in module, if there is no match, then python looks in sys.path
36
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
37
How do you import an object from a module?
from module import object1,object2.... This way you don't have to us dot notation and it saves memory
38
What directory must a package include in order for its contents to be accessed?
__init__.py
39
How do you import a module from a package?
from import
40
How do you import an object inside a module inside a package?
from import
41
What is the difference between import y.z and from x.y import z
The z in the first scenario has to be a package, subpackage, or a module The z in the second scenario has can also be an object in a module
42
What modules are built-in to python?
- math - os - sys - copy - time - pdb - urllib - random - datetime
43
What function in matplotlib displays the graph?
.show()
44
What function in matplotlib plots the graph?
.plot(x,y, step of x axis) - x representing the x axis, could be a list - y representing the y axis if the x axis is left clear then it increase in increments of 1, starting at 0 (0, y[0]) (1, y[1])
45
What characters represent each variation of graph colour?
b =blue r = red g = green y = yellow c = cyan m = magenta w = white k = black
46
What characters represent each line variation for matplotlib graphs?
- = dashed line -- = solid line -. = dashed dotted line : = dotted line
47
What characters represent each variation of point marker of matplotlib graphs?
. = point marker , = pixel marker o = circle marker + = plus marker X = X marker v = triangle down maker ^ = triangle up marker > = triangle right marker * = star marker p = pentagon marker 1 = tri down marker 2 = tri up marker 3 = tri left marker 4 = tri right marker h = hexagon marker H = hexagon marker D = diamond marker d = thin diamond marker | = vertical line - = horizontal line maker s = square marker
48
What characters represent each variation of point marker of matplotlib graphs (not polygons)?
. = point marker , = pixel marker + = plus marker - = horizontal line maker X = X marker * = star marker 1 = tri down marker 2 = tri up marker 3 = tri left marker 4 = tri right marker | = vertical line
49
What are polygon markers for matplotlib?
s = square marker D = diamond marker d = thin diamond marker h = hexagon marker H = hexagon marker v = triangle down maker ^ = triangle up marker > = triangle right marker p = pentagon marker o = circle marker
50
What does the alpha property do for a graph?
enables transparency - float
51
What does the antialiased property do for a graph?
enable anti-aliasing of the line - boolean
52
What does the color property do for a graph?
changes colour of the line
53
What does the solid_capstyle property do for a graph?
How the cap of a line appears
54
What does the solid_joinstyle property do for a graph?
How the join of a line appears
55
What does the data property do for a graph?
The arrays of x and y coordinates
56
What does the label property do for a graph?
The label to use for the line
57
What does the linestyle property do for a graph?
The style of the line
58
What does the linewidth property do for a graph?
The width of the line when drawn
59
What does the marker property do for a graph?
The style of marker to use
60
What does the markersize property do for a graph?
The size of the marker
61
What does the visible property do for a graph?
Show/hide the line
62
what does .legend() do for a graph?
Create a key/legend
63
What does the text(x,y, string) function do?
create text to put on the graph
64
How is an array full of zeros declared?
import numpy as np np.zeros((rows,columns))
65
How do you declare a 1d array?
import numpy as np np.array([1,2,3])
66
what does array.linspace(num1,num2,total_nums) do?
take two numbers and create a list of values equally spaced between them, creating a total list of total_num values
67
What does the figure() function do?
Create multiple windows each with their own graphic plots using matplotlib
68
What does matplotlib.xlabel do(x/y)?
label the axis of a graph
69
How do you declare the axis of a plot?
plt.axis(x_min,x_max,y_min,y_max)
70
What does plt.subplot() do?
create multiple plots on one figure, determined using the parameters: subplot(rows, columns, location) the active sub plot/ location must be a plot on the figure, can only be a number between rows*columns
71
How do you create multiple axis?
left_axis = figure.adds_subplot(1,2,1) right_axis = left_axis.twin() creates a variable right_axis which can now be labeled: right_axis.set_ylabel('')
72
How do you create a histogram in python?
plt.hist()
73
What is the default bins parameter value?
10
74
How do you change the outline of a data point?
ec = 'character'
75
What does numpy.linspace(a,b,c) do?
create a range for an axis on a graph, c is the step
76
What does numpy.arange(d,e,f) do?
create a range for an axis on a graph, f is the step, d and e are not included in the range, unlike in numpy.linspace()
77
How do you create a legend?
plt.plot(x, y, label = 'graph 1') plt.plot(x, y, label = 'graph 2') plt.legend(loc = '')
78
How do you position a legend?
plt.legend(loc = 'location')
79
What does subplot() do?
Allow for multiple graphs to be shown in a figure
80
How do you make two graphs in a figure?
plt.figure() pl.subplot(211) plt.plot() plt.subplot(212) plot.plot() plt.show()
81
How do you add a grid to the graph?
plt.grid(True)
82
How do you remove the steps on an axis?
ax = subplot() ax.plot(...) ax.set_xticklabels([])
83
When setting a subplot = ax/some variable, how do you access the normal functions that could be used by plt? For example plt.ylabel = ax.?
Put 'set_' in front of the function: ax.set_ylabel('.....')
84
How do you create a list using linspace or arange?
import numpy as np a = list(np.linspace(a,b,c)) - create a list between a,b with c number of values - values are decimals b = list(np.arange(a,b,c)) - create a list between a,b (not including b) with c as the step
85
What happens when you divide an array by a constant?
All values are divided by the constant
86
Can lists be divided by a constant?
No, produces an error
87
Do the x and y axis have to have the same number of values in the list for a plot?
yes
88
How do you dot multiply two matricies?
np.dot(m1,m2) or answer = m1@m2
89
What does .strip() do?
get rid of \n and white space from either side of a string .lstrip() does from the right .rstrip() does from the left
90
What does separator.join(iterator) do?
iterates through each index of a string, list, or tuple and joins the elements together, divided by the separator specified
91
How do you prevent additional blank lines between writing lines?
open('file', 'designator', newline = '')
92
How do you write a row to a csv file?
reader = csv.reader(file) row = ['val','val','val'] reader.writerow(row)