Add sample_package with linear algebra tools

- add sample_package:
  + __init__.py => high-level description and imports
  + matrix.py => define a Matrix class
  + vector.py => define a Vector class
  + utils.py => package-wide utilities
- streamline the code snippets in the chapter 11 notebooks
  to align with the sample_package
This commit is contained in:
Alexander Hess 2020-10-27 16:41:22 +01:00
commit 6bcfff481c
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
7 changed files with 770 additions and 40 deletions

View file

@ -1815,17 +1815,16 @@
},
"outputs": [],
"source": [
"def norm(vector_or_matrix):\n",
"def norm(vec_or_mat):\n",
" \"\"\"Calculate the Frobenius or Euclidean norm of a matrix or vector.\n",
"\n",
" Args:\n",
" vector_or_matrix (Vector/Matrix): the entries whose squares\n",
" are summed up\n",
" vec_or_mat (Vector / Matrix): object whose entries are squared and summed up\n",
"\n",
" Returns:\n",
" norm (float)\n",
" \"\"\"\n",
" return math.sqrt(sum(x ** 2 for x in vector_or_matrix))"
" return math.sqrt(sum(x ** 2 for x in vec_or_mat))"
]
},
{