Maak de weergegeven objecten aan of pas de transformaties toe in NumPy. Print telkens het resultaat.
import numpy as npa = np.array([2, 5, 8, 11])
b = np.array([1, 3, 5, 7])
print(a)
print(b)[ 2 5 8 11]
[1 3 5 7]
B = np.array([[6.0, 7.0], [4.0, 3.0], [5.0, 2.0]])
print(B)[[6. 7.]
[4. 3.]
[5. 2.]]
print(B.T)[[6. 4. 5.]
[7. 3. 2.]]
print(B[1, 1])3.0
b + 7array([ 8, 10, 12, 14])A = np.array([[1.1, 2.5], [3.2, 4.4], [5.1, 6.9]])
print(A * B)[[ 6.6 17.5]
[12.8 13.2]
[25.5 13.8]]
p = np.dot(a, b) # or a @ b
print(p)134
c = np.array([3.8, 22.1])
p = np.dot(B, c) # or B @ c
print(p)[177.5 81.5 63.2]
l2_norm = np.sqrt(np.dot(b, b)) # or np.linalg.norm(b)
print(l2_norm)9.16515138991168
C = np.diag(np.array([5, 7, 1, 4]))
print(C)[[5 0 0 0]
[0 7 0 0]
[0 0 1 0]
[0 0 0 4]]
D = np.identity(7)
print(D)[[1. 0. 0. 0. 0. 0. 0.]
[0. 1. 0. 0. 0. 0. 0.]
[0. 0. 1. 0. 0. 0. 0.]
[0. 0. 0. 1. 0. 0. 0.]
[0. 0. 0. 0. 1. 0. 0.]
[0. 0. 0. 0. 0. 1. 0.]
[0. 0. 0. 0. 0. 0. 1.]]
E = np.array([[1.1, 2.5, 3.0], [3.2, 4.4, 3.5], [5.1, 6.9, 1.2]])
F = np.tril(E)
print(F)[[1.1 0. 0. ]
[3.2 4.4 0. ]
[5.1 6.9 1.2]]