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:
parent
2c83a883c5
commit
6bcfff481c
7 changed files with 770 additions and 40 deletions
|
|
@ -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))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue