1/58
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What does NumPy stand for:
Numerical Python
The core Numpy array object is called:
ndarray
Which creates a 1D NumPy array:
np.array ([1, 2, 3])
Which call makes an array of zeros with shape (100,30):
np.zeros ((100,30))
np.eye(10) creates:
A 10x10 identity matrix
If A=np.array ([[1, 2], [3, 4], [5, 6]]), then A/1000 is:
Elementwise division by 1000
np.argmax(e) returns:
The index (position) of the maximum value in e (flattened index)
Which compares arrays element-by-element for equality:
np.equal (A,B)
np.less_equal (A,B) returns:
A boolean array of elementwise comparisons (A is less than or equal to B)
If f=np.array ([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 78]]), then f[1, 2] is:
7
The safe way to make an independent copy is:
copy_arr = arr1.copy( )
Which operator does matrix multiplication for NumPy arrays:
@
For a 2D array d, np.sort (d, axis = 0) sorts:
Each column
What is the most common convention for importing pyplot:
Import matoplotlib as plt
In Matplotlib, the figure is best described as:
The plotting area inside the axes. Also could be, the top-level container ("canvas/window") holding everything
In Matplotlib, an Axes object is:
The area where data is plotted (with x/y axes, ticks, labels)
Which command creates a simple line plot:
plt.plot (x, y)
Which functions set x-label, y-label, and title (pyplot style):
plt.xlabel( ), plt.ylabel( ), plt.title( )
np.linespace (-10, 10, 1000) produces:
1000 evenly spaced values between -10 and 10
plt.subplot (1, 2, 1) means:
1 row, 2 columns, first subplot
Which is object-oriented Matplotlib usage:
ax.plot(x, y) after creating fig, ax=plt.subplots( )
Which creates an empty figure in OO style:
fig = plt.subplots( )
fig.add_axes ([0.1, 0.2, 0.8, 0.9]) uses a list that represents:
[left, bottom, width, height] in figure fraction (0-1)
Which is the OO equivalent of plt.title ("My Plot"):
ax.set_title("My Plot")
Which is the OO equivalent of plt.xlabel("x"):
ax.set_xlabel("x")
What does fig, axes=plt.subplots (nrows=3, ncols=3) create:
A 3x3 grid of axes objects
Why use plt.tight_layout( ) (as shown in lecture notebook):
To automatically adjust spacing so labels don't overlap
In plt.figure (figsize = (8, 2), dpi=100), figsize is measured in:
Inches
Increasing dpi generally results in:
Higher resolution (more pixels) when saving
Which command saves a figure in your notebook:
fig.savefig ("my_figure.jpg")
Which plot type is best for showing a distribution of values:
Histogram
plt.hist (x, bins = 100, color = "red"), what does bins=100 control:
The number of histogram bars (bin count)
Which function displays an image array on axes (have not learned this yet), internet says:
plt.imshow( )
Images are read using (have not learned this yet), internet says:
plt.imread(...) only
A pandas bar plot created using my_df.plot.bar ( ):
Uses Matplotlib under the hood to render
What is the main purpose of numerical methods?
To approximate solutions when exact algebraic solutions are difficult or impossible
Numerical methods are commonly used for solving (didn't get this answer, internet says):
Integrals, differential equations, and nonlinear equations
A numerical method usually works by:
Constructing successive approximations to the solution
A lambda function in Python is:
A small anonymous function with one expression
Which is the correct general syntax for a lambda function?
lambda arguments: expression
Which Python function applies a given function to every item in an iterable?
map( )
Given the following code,
import numpy as np
ar = np.array([ (l(2, 5), (3, 71))
Which of the following is not the result of the reshape function?
[[2 3]
[57]]
What condition must be met for two matrices, A and B, to be compatible for matrix multiplication A xB?
The number of columns in A must equal the number of rows in B.
How does memory efficiency differ between NumPy arrays and Python lists?
NumPy arrays use less memory because they store elements of the same data type in a contiguous block of memory.
Which of the following commands reshapes an array arr into a shape of 3 rows and 4 columns?
p.reshape(arr, (3, 4))
Which NumPy function is used to compute the inverse of a matrix?
np.linalg.inv( )
How does element-wise operation differ between NumPy arrays and Python lists?
NumPy arrays support element-wise operations directly, while Python lists require loops. (Needs loops)
What is the correct syntax to define a lambda function to calculate the length of hypotenuse of a right-angled triangle?
f = lambda a,b: (a*2+b2) *0.5
Suppose, you are using Bisection method to find the root of a function f(x). At one stage during the process, you have the upper endpoint, xu =2.5, lower endpoint xl = 2.4, middle point xm = 2.45; evaluating the function at these points result as: f(xu) > 0, f(x) < 0 and f(xm) > 0. From this step onwards, what is going to be your next assumption for the root (i.e. xm)?
2.425
Which of the following statements best defines approximate relative error?
The absolute difference between the approximate value and the previous approximation, divided by the current approximation, expressed as a percentage.
What of the following are true regarding differences between the bisection and secant methods to find roots?
A. Both methods require two initial guesses (starting points).
B. Unlike the secant method, the bisection requires the initial two guesses to cover (bracket) the root.
C. Unlike the bisection method, the secant method might not converge.
D. All of the choices.
D.
Which of the following pair of numbers is a valid bracketing interval for solving the equation:
3x=12
[-2, 10]
Please choose the correct description of output of the following code:
matplotlib.pyplot.plot(x1,y1)
matpTotib.pyplot.plot(x2,y2)
matplotlib.pyplot.show
Prints 1 figure that plots 2 different datasets
Which of the following codes does not produce a plot?:
import matplotlib pyplot as plt
import numpy as np
f=lambda x: x**3
pit.plot (f, -10, 10)
How would setting too few bins in a Matplotlib histogram affect the plot?
It would show fewer, wider bars, potentially oversimplifying the data distribution.
You are assuming a projectile's height is somehow related to time. If you have the data of the height of a projected object recorded over the timespan of its motion, what type of plot would be most appropriate to visualize the underlying relationship between height and time for the projectile?
Line plot
When importing a user-defined module in Python, what file extension should the module typically have:
.py
What does the following code do?
file = open (my _file.txt, a)
file. write("This is some new text.")
file.close( )
Appends "This is some new text." to the end of my _file.txt.
Why is it important to close a file after opening it in Python?
A. It frees up system resources used by the file.
B. It saves the changes made to the file during the program.
C. It prevents data corruption and memory leaks.
D. All of the choices
D.