Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Maak de weergegeven objecten aan of pas de transformaties toe in NumPy. Print telkens het resultaat.

import numpy as np
a=[25811]Tb=[1357]T\begin{align} \pmb{a} &= \begin{bmatrix} 2 & 5 & 8 & 11 \end{bmatrix}^T \cr \pmb{b} &= \begin{bmatrix} 1 & 3 & 5 & 7 \end{bmatrix}^T \end{align}
a = 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=[6.07.04.03.05.02.0]\pmb{B} = \begin{bmatrix} 6.0 & 7.0 \cr 4.0 & 3.0 \cr 5.0 & 2.0 \end{bmatrix}
B = np.array([[6.0, 7.0], [4.0, 3.0], [5.0, 2.0]])
print(B)
[[6. 7.]
 [4. 3.]
 [5. 2.]]
BT\pmb{B}^T
print(B.T)
[[6. 4. 5.]
 [7. 3. 2.]]
B2,2B_{2,2}
print(B[1, 1])
3.0
b+7\pmb{b}+7
b + 7
array([ 8, 10, 12, 14])
A=[1.12.53.24.45.16.9]AโŠ™B\begin{align} \pmb{A} &= \begin{bmatrix} 1.1 & 2.5 \cr 3.2 & 4.4 \cr 5.1 & 6.9 \end{bmatrix} \cr \pmb{A} &\odot \pmb{B} \end{align}
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]]
aTb\pmb{a}^T\pmb{b}
p = np.dot(a, b)  # or a @ b
print(p)
134
c=[3.822.1]TBc\begin{align} \pmb{c} &= \begin{bmatrix} 3.8 & 22.1 \end{bmatrix}^T \cr &\pmb{B}\pmb{c} \end{align}
c = np.array([3.8, 22.1])
p = np.dot(B, c)  # or B @ c
print(p)
[177.5  81.5  63.2]
โˆฃโˆฃbโˆฃโˆฃ2||\pmb{b}||_2
l2_norm = np.sqrt(np.dot(b, b))  # or np.linalg.norm(b)
print(l2_norm)
9.16515138991168
C=diag(5,7,1,4)C = diag(5, 7, 1, 4)
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=I7\pmb{D} = \pmb{I}_{7}
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=[1.12.53.03.24.43.55.16.91.2]F=tril(E)\begin{align} \pmb{E} &= \begin{bmatrix} 1.1 & 2.5 & 3.0 \cr 3.2 & 4.4 & 3.5 \cr 5.1 & 6.9 & 1.2 \end{bmatrix} \cr F &= \text{tril}(E) \end{align}
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]]