|
@@ -1,74 +1,77 @@
|
|
import numpy as np
|
|
import numpy as np
|
|
|
|
|
|
-a = np.array([3, 2, 1], ?)
|
|
|
|
|
|
+a = np.array([3, 2, 1], dtype="uint8")
|
|
|
|
|
|
assert a.dtype == "uint8"
|
|
assert a.dtype == "uint8"
|
|
|
|
|
|
-b = ?
|
|
|
|
|
|
+b = np.zeros([5, 5])
|
|
|
|
|
|
assert b.shape == (5, 5) and b.sum() == 0
|
|
assert b.shape == (5, 5) and b.sum() == 0
|
|
|
|
|
|
-c = ?
|
|
|
|
|
|
+c = np.ones([2, 2, 2])
|
|
|
|
|
|
assert c.ndim == 3 and c.sum() / c.size == 1
|
|
assert c.ndim == 3 and c.sum() / c.size == 1
|
|
|
|
|
|
-d = ?
|
|
|
|
|
|
+# Любой из вариантов сработает
|
|
|
|
+d = np.array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4])
|
|
|
|
+d = np.array([[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]])
|
|
|
|
+d = np.array([[[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]], [[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]]])
|
|
|
|
|
|
assert np.all(d == np.array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]))
|
|
assert np.all(d == np.array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]))
|
|
|
|
|
|
-e = ?
|
|
|
|
|
|
+e = np.array([[0., 0.25, 0.5, 0.75, 1.0]])
|
|
|
|
|
|
assert np.all(e == np.array([0., 0.25, 0.5, 0.75, 1.0]))
|
|
assert np.all(e == np.array([0., 0.25, 0.5, 0.75, 1.0]))
|
|
|
|
|
|
f = np.arange(5 * 5).reshape(5, 5)
|
|
f = np.arange(5 * 5).reshape(5, 5)
|
|
-fc = ?
|
|
|
|
|
|
+fc = f[0:6:2, 1:4:2]
|
|
|
|
|
|
assert np.all(fc == np.array([[1, 3], [11, 13], [21, 23]]))
|
|
assert np.all(fc == np.array([[1, 3], [11, 13], [21, 23]]))
|
|
|
|
|
|
g = np.ones((5, 3))
|
|
g = np.ones((5, 3))
|
|
-gc = ?
|
|
|
|
|
|
+gc = g.reshape(3, 5) * 3
|
|
|
|
|
|
assert np.all(gc == np.array([3., 3., 3., 3., 3.]))
|
|
assert np.all(gc == np.array([3., 3., 3., 3., 3.]))
|
|
|
|
|
|
h = np.arange(5) + 1
|
|
h = np.arange(5) + 1
|
|
-hc = ?
|
|
|
|
|
|
+hc = h * 2
|
|
|
|
|
|
assert np.all(hc == np.array([2., 4., 6., 8., 10.]))
|
|
assert np.all(hc == np.array([2., 4., 6., 8., 10.]))
|
|
|
|
|
|
j = np.array([1, 2, 3, 4, 9, 7, 11, 12, 15, 14, 33])
|
|
j = np.array([1, 2, 3, 4, 9, 7, 11, 12, 15, 14, 33])
|
|
-mask = ?
|
|
|
|
|
|
+mask = j % 3 == 0
|
|
jc = j[mask]
|
|
jc = j[mask]
|
|
|
|
|
|
assert np.all(jc == np.array([3, 9, 12, 15, 33]))
|
|
assert np.all(jc == np.array([3, 9, 12, 15, 33]))
|
|
|
|
|
|
k = np.array([1, 2, 3, 4, 5])
|
|
k = np.array([1, 2, 3, 4, 5])
|
|
l = np.array([2, 2, 3, 3, 4])
|
|
l = np.array([2, 2, 3, 3, 4])
|
|
-kl = ?
|
|
|
|
|
|
+kl = k ** l
|
|
|
|
|
|
assert np.all(kl == np.array([1, 4, 27, 64, 625]))
|
|
assert np.all(kl == np.array([1, 4, 27, 64, 625]))
|
|
|
|
|
|
m = np.array([2, 2, 2, 3, 3, 3])
|
|
m = np.array([2, 2, 2, 3, 3, 3])
|
|
-mc = ?
|
|
|
|
|
|
+mc = m.std()
|
|
|
|
|
|
assert mc == 0.5
|
|
assert mc == 0.5
|
|
|
|
|
|
n = np.array([1, 2, 3, 4, 5, 6])
|
|
n = np.array([1, 2, 3, 4, 5, 6])
|
|
-nc = ?
|
|
|
|
|
|
+nc = n.mean()
|
|
|
|
|
|
assert nc == 3.5
|
|
assert nc == 3.5
|
|
|
|
|
|
o = np.array([2, 2, 2, 2])
|
|
o = np.array([2, 2, 2, 2])
|
|
-oc = ?
|
|
|
|
|
|
+oc = o.reshape(2, 2)
|
|
|
|
|
|
assert oc.ndim == 2 and oc.shape == (2, 2)
|
|
assert oc.ndim == 2 and oc.shape == (2, 2)
|
|
|
|
|
|
p = np.array([1, 2, 3, 4])
|
|
p = np.array([1, 2, 3, 4])
|
|
-pc = ?
|
|
|
|
|
|
+pc = np.flip(p)
|
|
|
|
|
|
assert np.all(pc == np.array([4, 3, 2, 1]))
|
|
assert np.all(pc == np.array([4, 3, 2, 1]))
|
|
|
|
|
|
r = np.array([3, 3, 5, 5])
|
|
r = np.array([3, 3, 5, 5])
|
|
-rc = ?
|
|
|
|
|
|
+rc = r.copy()
|
|
rc[1:3] = -1
|
|
rc[1:3] = -1
|
|
|
|
|
|
-assert np.all(r[1:3] == np.array([3, 5])) and np.all(rc[1:3] == np.array([-1, -1]))
|
|
|
|
|
|
+assert np.all(r[1:3] == np.array([3, 5])) and np.all(rc[1:3] == np.array([-1, -1]))
|