# Vector Norm


```python
import numpy as np
from scipy import signal
from scipy.spatial import distance
```


```python
A = np.array([1+1j, 2+2j, 3+3j, 4+4j, 5+5j])
B = np.array([6-6j, 7-7j, 8-8j, 9-9j, 10-10j])
C = np.array([2,3,5,7,11])
Z = np.array([0,0,0,0,0])

D = np.array([A,B])
```

For every complex inner product space V(-,-), we can define a norm or length which is a function defined as   
\begin{align}
  | |: V -> E  
\end{align}
defined as  
\begin{align}
  |V| = |\sqrt{V . V}|
\end{align}


```python
[
np.linalg.norm(A) == np.abs(np.sqrt(np.dot(A,A))),
np.linalg.norm(B) == np.abs(np.sqrt(np.dot(B,B))),
np.linalg.norm(C) == np.abs(np.sqrt(np.dot(C,C)))
]
```




    [True, True, True]




```python
[
    np.linalg.norm(A),    
    np.linalg.norm(B),    
    np.linalg.norm(C),
]
```




    [10.488088481701515, 25.69046515733026, 14.422205101855956]



# Vector Distance

For every complex inner product space V(-,-), we can define a distance function 
\begin{align}
      d(,) : V x V -> E
\end{align}
where
\begin{align}
      d(V1,V2) : |V1 - V2| = \sqrt{V1-V2, V1-V2}
\end{align}


```python
distance.euclidean(A, B)
```




    27.748873851023216




```python
np.linalg.norm(A-B) == distance.euclidean(A, B)
```




    True




```python
np.round(  distance.euclidean(A, B),                 10) == \
np.round(  np.abs(np.sqrt(np.dot(A,A)-np.dot(B,B))), 10)
```




    True



Distance is symmetric: d(V, W) = d(W, V)


```python
distance.euclidean(A, B) == distance.euclidean(B, A)
```




    True



Distance satisfies the triangle inequality: d(U, V) ≤ d(U, W) + d(W, V)


```python
distance.euclidean(A, C), distance.euclidean(A, B) + distance.euclidean(B, C)
```




    (10.295630140987, 47.13959328068853)




```python
distance.euclidean(A, C) <= distance.euclidean(A, B) +  distance.euclidean(B, C)
```




    True



Distance is nondegenerate: d(V, W) > 0 if V ≠ W and d(V, V) = 0.


```python
distance.euclidean(Z,Z)
```




    0.0




```python
distance.euclidean(A,Z), distance.euclidean(A,Z) > 0
```




    (10.488088481701515, True)



## Orthogonal Vectors

The dot product of orthogonal vectors is zero


```python
X = np.array([1,0])
Y = np.array([0,1])
```


```python
np.dot(X,Y)
```




    0



## Kronecker Delta

δj,k is called the Kronecker delta function.

δj,k =  
  1 (if i == j);  
  0 (if i != j);  


```python
M = np.matrix([[1,2,3],[4,5,6],[7,8,9]]); X
```




    array([1, 0])




```python
{ "shape": M.shape, "size": M.size }
```




    {'shape': (3, 3), 'size': 9}




```python
def kronecker_delta(matrix):
    output = np.copy(matrix)
    for i in range(0, matrix.shape[0]):
        for j in range(0, matrix.shape[1]):
            output[i,j] = output[i,j] if i == j else 0
    return output
```


```python
kronecker_delta(M)
```




    array([[1, 0, 0],
           [0, 5, 0],
           [0, 0, 9]])



It is equlivant to element wise multiplication by the identity matrx


```python
np.multiply(M, np.identity(3))
```




    matrix([[1., 0., 0.],
            [0., 5., 0.],
            [0., 0., 9.]])




```python
kronecker_delta(M) == np.multiply(M, np.identity(M.shape[0]))
```




    matrix([[ True,  True,  True],
            [ True,  True,  True],
            [ True,  True,  True]])



NOTE: np.kron is the Kronecker (tensor) product function, and not the Kronecker DELTA


```python
np.kron(M,M)
```




    matrix([[ 1,  2,  3,  2,  4,  6,  3,  6,  9],
            [ 4,  5,  6,  8, 10, 12, 12, 15, 18],
            [ 7,  8,  9, 14, 16, 18, 21, 24, 27],
            [ 4,  8, 12,  5, 10, 15,  6, 12, 18],
            [16, 20, 24, 20, 25, 30, 24, 30, 36],
            [28, 32, 36, 35, 40, 45, 42, 48, 54],
            [ 7, 14, 21,  8, 16, 24,  9, 18, 27],
            [28, 35, 42, 32, 40, 48, 36, 45, 54],
            [49, 56, 63, 56, 64, 72, 63, 72, 81]])



c5d33c665178899608ed190c5ef58e52b0d0d40d
ipynb
Jupyter Notebook
juypter/notebooks/linear-algebra/5_vector_norm.ipynb
JamesMcGuigan/ecosystem-research
bfd98bd5b0a2165f449eb36b368b54fe972374fe
MIT
2019-01-01T02:04:27.000Z
2019-01-01T02:04:27.000Z
juypter/notebooks/linear-algebra/5_vector_norm.ipynb
JamesMcGuigan/ecosystem-research
bfd98bd5b0a2165f449eb36b368b54fe972374fe
MIT
2020-03-09T17:51:00.000Z
2020-03-09T17:51:00.000Z
juypter/notebooks/linear-algebra/5_vector_norm.ipynb
JamesMcGuigan/ecosystem-research
bfd98bd5b0a2165f449eb36b368b54fe972374fe
MIT
Qwen/Qwen-72B
1. YES
2. YES