Comp Thinking Exam 2

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/58

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:15 PM on 3/26/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

59 Terms

1
New cards

What does NumPy stand for:

Numerical Python

2
New cards

The core Numpy array object is called:

ndarray

3
New cards

Which creates a 1D NumPy array:

np.array ([1, 2, 3])

4
New cards

Which call makes an array of zeros with shape (100,30):

np.zeros ((100,30))

5
New cards

np.eye(10) creates:

A 10x10 identity matrix

6
New cards

If A=np.array ([[1, 2], [3, 4], [5, 6]]), then A/1000 is:

Elementwise division by 1000

7
New cards

np.argmax(e) returns:

The index (position) of the maximum value in e (flattened index)

8
New cards

Which compares arrays element-by-element for equality:

np.equal (A,B)

9
New cards

np.less_equal (A,B) returns:

A boolean array of elementwise comparisons (A is less than or equal to B)

10
New cards

If f=np.array ([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 78]]), then f[1, 2] is:

7

11
New cards

The safe way to make an independent copy is:

copy_arr = arr1.copy( )

12
New cards

Which operator does matrix multiplication for NumPy arrays:

@

13
New cards

For a 2D array d, np.sort (d, axis = 0) sorts:

Each column

14
New cards

What is the most common convention for importing pyplot:

Import matoplotlib as plt

15
New cards

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

16
New cards

In Matplotlib, an Axes object is:

The area where data is plotted (with x/y axes, ticks, labels)

17
New cards

Which command creates a simple line plot:

plt.plot (x, y)

18
New cards

Which functions set x-label, y-label, and title (pyplot style):

plt.xlabel( ), plt.ylabel( ), plt.title( )

19
New cards

np.linespace (-10, 10, 1000) produces:

1000 evenly spaced values between -10 and 10

20
New cards

plt.subplot (1, 2, 1) means:

1 row, 2 columns, first subplot

21
New cards

Which is object-oriented Matplotlib usage:

ax.plot(x, y) after creating fig, ax=plt.subplots( )

22
New cards

Which creates an empty figure in OO style:

fig = plt.subplots( )

23
New cards

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)

24
New cards

Which is the OO equivalent of plt.title ("My Plot"):

ax.set_title("My Plot")

25
New cards

Which is the OO equivalent of plt.xlabel("x"):

ax.set_xlabel("x")

26
New cards

What does fig, axes=plt.subplots (nrows=3, ncols=3) create:

A 3x3 grid of axes objects

27
New cards

Why use plt.tight_layout( ) (as shown in lecture notebook):

To automatically adjust spacing so labels don't overlap

28
New cards

In plt.figure (figsize = (8, 2), dpi=100), figsize is measured in:

Inches

29
New cards

Increasing dpi generally results in:

Higher resolution (more pixels) when saving

30
New cards

Which command saves a figure in your notebook:

fig.savefig ("my_figure.jpg")

31
New cards

Which plot type is best for showing a distribution of values:

Histogram

32
New cards

plt.hist (x, bins = 100, color = "red"), what does bins=100 control:

The number of histogram bars (bin count)

33
New cards

Which function displays an image array on axes (have not learned this yet), internet says:

plt.imshow( )

34
New cards

Images are read using (have not learned this yet), internet says:

plt.imread(...) only

35
New cards

A pandas bar plot created using my_df.plot.bar ( ):

Uses Matplotlib under the hood to render

36
New cards

What is the main purpose of numerical methods?

To approximate solutions when exact algebraic solutions are difficult or impossible

37
New cards

Numerical methods are commonly used for solving (didn't get this answer, internet says):

Integrals, differential equations, and nonlinear equations

38
New cards

A numerical method usually works by:

Constructing successive approximations to the solution

39
New cards

A lambda function in Python is:

A small anonymous function with one expression

40
New cards

Which is the correct general syntax for a lambda function?

lambda arguments: expression

41
New cards

Which Python function applies a given function to every item in an iterable?

map( )

42
New cards

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]]

43
New cards

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.

44
New cards

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.

45
New cards

Which of the following commands reshapes an array arr into a shape of 3 rows and 4 columns?

p.reshape(arr, (3, 4))

46
New cards

Which NumPy function is used to compute the inverse of a matrix?

np.linalg.inv( )

47
New cards

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)

48
New cards

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

49
New cards

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

50
New cards

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.

51
New cards

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.

52
New cards

Which of the following pair of numbers is a valid bracketing interval for solving the equation:

3x=12

[-2, 10]

53
New cards

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

54
New cards

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)

55
New cards

How would setting too few bins in a Matplotlib histogram affect the plot?

It would show fewer, wider bars, potentially oversimplifying the data distribution.

56
New cards

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

57
New cards

When importing a user-defined module in Python, what file extension should the module typically have:

.py

58
New cards

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.

59
New cards

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.

Explore top notes

note
AP Gov: Chapter 1 Vocab
Updated 1299d ago
0.0(0)
note
Unit 7: Evolution (Biology)
Updated 710d ago
0.0(0)
note
Mitosis
Updated 751d ago
0.0(0)
note
diplomacy
Updated 1251d ago
0.0(0)
note
Le Chatelier's Principle
Updated 1158d ago
0.0(0)
note
AP Gov: Chapter 1 Vocab
Updated 1299d ago
0.0(0)
note
Unit 7: Evolution (Biology)
Updated 710d ago
0.0(0)
note
Mitosis
Updated 751d ago
0.0(0)
note
diplomacy
Updated 1251d ago
0.0(0)
note
Le Chatelier's Principle
Updated 1158d ago
0.0(0)

Explore top flashcards

flashcards
Kite Runners Vocab
35
Updated 68d ago
0.0(0)
flashcards
Midterm
238
Updated 389d ago
0.0(0)
flashcards
Describing People SPN2 PreAP
91
Updated 221d ago
0.0(0)
flashcards
Cellular Respiration Review
22
Updated 1215d ago
0.0(0)
flashcards
apush 3.1-3.4
52
Updated 578d ago
0.0(0)
flashcards
Chapter 9 Med Term
25
Updated 1217d ago
0.0(0)
flashcards
Posterior Muscles
47
Updated 1244d ago
0.0(0)
flashcards
SALUD Y BIENESTAR vocabulario
33
Updated 913d ago
0.0(0)
flashcards
Kite Runners Vocab
35
Updated 68d ago
0.0(0)
flashcards
Midterm
238
Updated 389d ago
0.0(0)
flashcards
Describing People SPN2 PreAP
91
Updated 221d ago
0.0(0)
flashcards
Cellular Respiration Review
22
Updated 1215d ago
0.0(0)
flashcards
apush 3.1-3.4
52
Updated 578d ago
0.0(0)
flashcards
Chapter 9 Med Term
25
Updated 1217d ago
0.0(0)
flashcards
Posterior Muscles
47
Updated 1244d ago
0.0(0)
flashcards
SALUD Y BIENESTAR vocabulario
33
Updated 913d ago
0.0(0)