General note: The following code is executed as the first cell of the notebook in which all other problems’ codes are run.
import numpy as npfrom scipy.integrate import solve ivp import scipy.stats as stimport matplotlib.pyplot as plt
1. What is the output of this code
a = np.ones((1, 3))b = np.ones((3, 1))c = a @ bprint(int(c))
| A | B | C | D | E | F | G | H |
|----|----|----|---|---|---|---|-------|
| -9 | -3 | -1 | 0 | 1 | 0 | 9 | Error |
2. What is the output of this code?
a = np.array(range(100)).reshape((10, -1)) b = np.array(range(100)).reshape((10, -1))c = a @ bprint(c[0, 0])
| A | B | C | D | E | F | G | H | K | L |
|---|----|-----|-----|-----|------|------|------|-------|-------|
| 1 | 10 | 100 | 285 | 385 | 2850 | 3355 | 7495 | 28500 | 29410 |
3. What is the output of this code?
4. What is the output of this code?
5. What is the output of this code?
6. What is the output of this code?
7. Which of the following variables are True?
8. What complexity does the Insertion Sort algorithm have in the worst case?
Answer must contain: (time complexity / space complexity).
A. O(n)/O(1)
B. O(n)/O(n)
C. O(log(n))/O(1)
D. O(log(n))/O(n)
E. O(nlog(n))/O(1)
F. O(nlog(n))/O(n)
G. O(nlog(n2))/O(1)
H. O(nlog(n2))/O(n)
K. O(n2)/O(1)
L. O(n2)/O(n)
9. What complexity does the insertion in doubly-linked list have in the worst case?
Answer must contain: (time complexity / space complexity).
import math
from sympy import *
x = Symbol('x')
y = Symbol('y')
r = diff(log(x**y), x)
r. evalf(subs={
x: math.pi,
y: math.pi**3
})
| A | B | C | D | E | F | G | H | K | L |
|----|----|---|------|------|------|------|------|------|-------|
| -1 | -0 | 1 | 0.32 | 1.14 | 2.29 | 3.14 | 9.87 | 11.3 | Error |
import random
a = np.array([random.gauss(mu=3., sigma=2.)
for i in range(int(1e5))]).mean()
b = np.array([random.random()
for i in range(int(1e5))]).mean()
print(round(a+b, 1))
| A | B | C | D | E | F | G | H | K | L |
|---|-----|---|-----|---|-----|---|-----|---|-----|
| 1 | 1.5 | 2 | 2.5 | 3 | 3.5 | 4 | 4.5 | 5 | 5.5 |
s = [-1, 2]
a = np.arange(1, 5).reshape(s)
b = np.arange(6).reshape(s[::-1])
c = np.where(a == b[:2, :2], a, 0)
print(sum(c[:, 0] - c[:, 1]))
| A | B | C | D | E | F | G | H | K | L |
|----|----|----|----|---|---|---|---|---|-------|
| -6 | -5 | -2 | -1 | 0 | 1 | 2 | 5 | 6 | Error |
def mystery_function(n):
if n <= 1:
return 1
else:
return n * (mystery_function(n - 1))
print(mystery_function(5))
| A | B | C | D | E | F | G | H | K | L | M | N | P | U | R | S |
|------|------|-----|-----|-----|-----|----|---|---|----|----|----|----|-----|-----|-------|
| -720 | -120 | -24 | -18 | -15 | -11 | -1 | 0 | 1 | 11 | 15 | 18 | 24 | 120 | 720 | Error |
import time
from numba import jit
def loop_mean(n):
lst = list()
for i in range(n):
lst.append(i)
return sum(lst) / len(lst)
def compr_mean(n):
lst = [i for i in range(n)]
return sum(lst) / len(lst)
def np_mean(n):
arr = np.arange(n)
return arr.mean()
@jit(nopython=True)
def numba_mean(n):
lst = list()
for i in range(n):
lst.append(i)
return sum(lst) / len(lst)
def measure_time(fn, arg):
start = time.time()
_ = fn(arg)
return time.time() - start
n = int(1e1)
e1_loop_time = measure_time(loop_mean, n)
e1_compr_time = measure_time(compr_mean, n)
e1_np_time = measure_time(np_mean, n)
e1_numba_time = measure_time(numba_mean, n)
n = int(1e6)
e6_loop_time = measure_time(loop_mean, n)
e6_compr_time = measure_time(compr_mean, n)
e6_numba_time = measure_time(numba_mean, n)
e6_np_time = measure_time(np_mean, n)
a = e6_loop_time > e6_compr_time > e6_numba_time > e6_np_time
b = e1_loop_time > e1_compr_time > e1_numba_time > e1_np_time
c = e6_loop_time > e6_compr_time > e6_np_time > e6_numba_time
d = e1_loop_time > e1_compr_time > e1_np_time > e1_numba_time
e = e6_compr_time > e6_loop_time > e6_numba_time > e6_np_time
f = e1_compr_time > e1_loop_time > e1_numba_time > e1_np_time
g = e6_compr_time > e6_loop_time > e6_np_time > e6_numba_time
h = e1_compr_time > e1_loop_time > e1_np_time > e1_numba_time
| A | B | C | D | E | F | G | H | K | L | M | N | P | U | R | S | T | W |
|---|---|---|---|---|---|---|---|-----|-----|-----|-----|-----|-----|-----|-----|-----|----|
| a | b | c | d | e | f | g | h | a,b | c,d | e,f | g,h | a,c | b,d | e,g | f,h | All | No |
from matplotlib import cm
plt.style.use('_mpl-gallery')
сmар = cm.Oranges
l = 4
step = 0.2
X = np.arange(-l, l, step)
Y = np.arange(-l, l, step)
X, Y = np.meshgrid(X, Y)
Z = Y**2 + 10 * np.sin(X)
fig,ax = plt.subplots(
subplot_kw={'projection': '3d'},
figsize=(8, 8)) ax.plot_surface(X, Y, Z, vmin=Z.min() * 2,
cmap=cmap
)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()