Difference between revisions of "User:Praveer-mathur-9f3d@uni-bonn.de/python-on-hpc"
Jump to navigation
Jump to search
| (One intermediate revision by the same user not shown) | |||
| Line 190: | Line 190: | ||
=== Short Quiz: Array Shapes, Broadcasting === <!--T:5--> | === Short Quiz: Array Shapes, Broadcasting === <!--T:5--> | ||
| − | Consider the following code. What does each print statement output? Could be an error. Treat all print statements independently. | + | Consider the following code. What does each print statement output? Could be an error. Treat all print statements independently. (Hard to implement) |
<code>x = np.zeros(5) <br> y = np.zeros((3, 5)) <br> z = np.zeros((5, 3, 1))</code> | <code>x = np.zeros(5) <br> y = np.zeros((3, 5)) <br> z = np.zeros((5, 3, 1))</code> | ||
| Line 284: | Line 284: | ||
=== Short Quiz: Advanced Indexing === <!--T:5--> | === Short Quiz: Advanced Indexing === <!--T:5--> | ||
| − | Consider the following code. What does each print statement output? Could be an error. Treat all print statements independently. | + | Consider the following code. What does each print statement output? Could be an error. Treat all print statements independently. (Hard to implement) |
<code>a = np.array([[1, 2, 3] [4, 5, 6]]) <br> idx = np.array([0, 0]) <br> mask = np.array([False, True, True])</code> | <code>a = np.array([[1, 2, 3] [4, 5, 6]]) <br> idx = np.array([0, 0]) <br> mask = np.array([False, True, True])</code> | ||
Latest revision as of 15:07, 18 March 2026
Short Quiz: Python Packages
Which of these locations will Python search for packages by default?
Short Quiz: Virtual Environments
Which of the following statements is true?
Short Quiz: Conda vs. Pip
To which package manager do the statements apply? pip, conda, neither or both?
"Non-Python packages available by default"
"Tightly integrated with its own virtual environment feature"
"Built-in third-party package repositories"
"Installs new Python executable into env by default"
"Automatically installs dependencies for requested package"
"Requires you to specify package version"
Short Quiz: Arrays and Performance
What should you always do before you optimize your code's performance? (Hard to implement).
Short Quiz: Array Memory Layout
Which index varies fastest in a row-major layout, which varies fastest in a
column-major layout? (Hard to implement).
Which ordering do NumPy arrays have by default? More than one answer
may be correct.
Short Quiz: Array Shapes, Broadcasting
Consider the following code. What does each print statement output? Could be an error. Treat all print statements independently. (Hard to implement)
x = np.zeros(5)
y = np.zeros((3, 5))
z = np.zeros((5, 3, 1))
print((x + y).shape)
print((x + z).shape)
print((y + z).shape)
print(y[:2, :2].shape)
print(y[:2].shape)
print((y[:2] + x[:2]).shape)
print((y[..., np.newaxis] + z).shape)
print((y.ravel() + x[0]).shape)
Short Quiz: Advanced Indexing
Consider the following code. What does each print statement output? Could be an error. Treat all print statements independently. (Hard to implement)
a = np.array([[1, 2, 3] [4, 5, 6]])
idx = np.array([0, 0])
mask = np.array([False, True, True])
print(a[idx])
print(a[:, idx])
print(a[idx, :])
a[:, mask] = -1
print(a)