Skip to content

Commit

Permalink
Update 02_math_recap_linear_algebra.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
iacopomasi committed Mar 7, 2024
1 parent c39ffaa commit 9f62ebf
Showing 1 changed file with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "subslide"
Expand All @@ -148,7 +148,7 @@
" [ 0. 1. ]\n",
" [ 2. -3. ]]\n",
"Shape (3, 2)\n",
"Number of dimensions: 2\n",
"Number of dimension: 2\n",
"Number of elements: 6\n"
]
}
Expand Down Expand Up @@ -449,7 +449,7 @@
},
{
"cell_type": "code",
"execution_count": 68,
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "subslide"
Expand All @@ -462,7 +462,7 @@
"True"
]
},
"execution_count": 68,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -661,7 +661,7 @@
},
{
"cell_type": "code",
"execution_count": 73,
"execution_count": 5,
"metadata": {
"slideshow": {
"slide_type": "subslide"
Expand Down Expand Up @@ -697,7 +697,7 @@
"True"
]
},
"execution_count": 73,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -741,28 +741,38 @@
},
{
"cell_type": "code",
"execution_count": 74,
"execution_count": 11,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0 1 2]\n",
" [3 4 5]\n",
" [6 7 8]]\n"
]
},
{
"data": {
"text/plain": [
"array([ 3, 12, 21])"
"36"
]
},
"execution_count": 74,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Sum all the values across cols (cols will disappear)\n",
"# Sum all values across axis 1.\n",
"A.sum(axis=1, keepdims=False) #3 (cols are cancelled out)"
"print(A)\n",
"A.sum(axis=(0,1), keepdims=False) #3 (cols are cancelled out)"
]
},
{
Expand Down Expand Up @@ -858,7 +868,7 @@
},
{
"cell_type": "code",
"execution_count": 76,
"execution_count": 13,
"metadata": {
"slideshow": {
"slide_type": "subslide"
Expand All @@ -871,7 +881,7 @@
"True"
]
},
"execution_count": 76,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -1361,7 +1371,7 @@
"source": [
"# Einsum = Einstein summation\n",
"\n",
"A is $i\\times k$ and B is $k \\times =j$.\n",
"A is $i\\times k$ and B is $k \\times j$.\n",
"\n",
"$$ (A\\cdot B)_{ij} = \\sum_{k=1}^K A_{ik}\\cdot B_{kj}$$\n",
"\n",
Expand Down Expand Up @@ -1445,7 +1455,7 @@
"\n",
"Einsum way:\n",
"```python\n",
"C = np.einsum('ik,kj -> ij')\n",
"C = np.einsum('ik,kj -> ij', A, B)\n",
"```\n",
"\n",
"The usual way seems shorter."
Expand Down Expand Up @@ -1536,11 +1546,12 @@
}
],
"source": [
"A = np.array([0, 1, 2]) #1x3 3x4\n",
"B = np.array([[ 0, 1, 2, 3], # 0\n",
" [ 4, 5, 6, 7], # 1\n",
" [ 8, 9, 10, 11]]) # 2\n",
"A[:, np.newaxis] * B # we wanna do this np.newaxis is broad cast and tells \n",
" # numpy to put A as col vector"
" # numpy to put A as col vector "
]
},
{
Expand Down Expand Up @@ -1698,7 +1709,7 @@
},
{
"cell_type": "code",
"execution_count": 85,
"execution_count": 16,
"metadata": {
"slideshow": {
"slide_type": "subslide"
Expand Down

0 comments on commit 9f62ebf

Please sign in to comment.