Re-run Chapter 11 files with Python 3.12

This commit is contained in:
Alexander Hess 2024-04-08 17:03:29 +02:00
parent 1902eb2a50
commit c206a75f3c
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
7 changed files with 256 additions and 248 deletions

View file

@ -212,7 +212,7 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-fd81d962f516>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mA\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mA\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'tuple'" "\u001b[0;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'tuple'"
] ]
} }
@ -405,7 +405,7 @@
"\u001b[0;31mInit signature:\u001b[0m \u001b[0mVector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mInit signature:\u001b[0m \u001b[0mVector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m A one-dimensional vector from linear algebra.\n", "\u001b[0;31mDocstring:\u001b[0m A one-dimensional vector from linear algebra.\n",
"\u001b[0;31mType:\u001b[0m type\n", "\u001b[0;31mType:\u001b[0m type\n",
"\u001b[0;31mSubclasses:\u001b[0m \n" "\u001b[0;31mSubclasses:\u001b[0m "
] ]
}, },
"metadata": {}, "metadata": {},
@ -433,24 +433,24 @@
"\n", "\n",
"class Vector(builtins.object)\n", "class Vector(builtins.object)\n",
" | A one-dimensional vector from linear algebra.\n", " | A one-dimensional vector from linear algebra.\n",
" | \n", " |\n",
" | Methods defined here:\n", " | Methods defined here:\n",
" | \n", " |\n",
" | dummy_method(self)\n", " | dummy_method(self)\n",
" | A dummy method for illustration purposes.\n", " | A dummy method for illustration purposes.\n",
" | \n", " |\n",
" | ----------------------------------------------------------------------\n", " | ----------------------------------------------------------------------\n",
" | Data descriptors defined here:\n", " | Data descriptors defined here:\n",
" | \n", " |\n",
" | __dict__\n", " | __dict__\n",
" | dictionary for instance variables (if defined)\n", " | dictionary for instance variables\n",
" | \n", " |\n",
" | __weakref__\n", " | __weakref__\n",
" | list of weak references to the object (if defined)\n", " | list of weak references to the object\n",
" | \n", " |\n",
" | ----------------------------------------------------------------------\n", " | ----------------------------------------------------------------------\n",
" | Data and other attributes defined here:\n", " | Data and other attributes defined here:\n",
" | \n", " |\n",
" | dummy_variable = 'I am a vector'\n", " | dummy_variable = 'I am a vector'\n",
"\n" "\n"
] ]
@ -521,6 +521,7 @@
" '__format__',\n", " '__format__',\n",
" '__ge__',\n", " '__ge__',\n",
" '__getattribute__',\n", " '__getattribute__',\n",
" '__getstate__',\n",
" '__gt__',\n", " '__gt__',\n",
" '__hash__',\n", " '__hash__',\n",
" '__init__',\n", " '__init__',\n",
@ -632,13 +633,13 @@
"outputs": [ "outputs": [
{ {
"ename": "TypeError", "ename": "TypeError",
"evalue": "dummy_method() missing 1 required positional argument: 'self'", "evalue": "Vector.dummy_method() missing 1 required positional argument: 'self'",
"output_type": "error", "output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-16-829638f9c7cf>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mVector\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdummy_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[16], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mVector\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdummy_method\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: dummy_method() missing 1 required positional argument: 'self'" "\u001b[0;31mTypeError\u001b[0m: Vector.dummy_method() missing 1 required positional argument: 'self'"
] ]
} }
], ],
@ -859,13 +860,13 @@
"outputs": [ "outputs": [
{ {
"ename": "TypeError", "ename": "TypeError",
"evalue": "__init__() missing 1 required positional argument: 'data'", "evalue": "Vector.__init__() missing 1 required positional argument: 'data'",
"output_type": "error", "output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-23-bcda4006949f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mVector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[22], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mVector\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: __init__() missing 1 required positional argument: 'data'" "\u001b[0;31mTypeError\u001b[0m: Vector.__init__() missing 1 required positional argument: 'data'"
] ]
} }
], ],
@ -884,13 +885,13 @@
"outputs": [ "outputs": [
{ {
"ename": "TypeError", "ename": "TypeError",
"evalue": "__init__() takes 2 positional arguments but 4 were given", "evalue": "Vector.__init__() takes 2 positional arguments but 4 were given",
"output_type": "error", "output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-24-e00314c6a560>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mVector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[23], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mVector\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: __init__() takes 2 positional arguments but 4 were given" "\u001b[0;31mTypeError\u001b[0m: Vector.__init__() takes 2 positional arguments but 4 were given"
] ]
} }
], ],
@ -925,8 +926,8 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-25-7261658e317e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mVector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[24], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mVector\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;32m<ipython-input-17-441d7f5df856>\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 18\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"a vector must have at least one entry\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[17], line 18\u001b[0m, in \u001b[0;36mVector.__init__\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_entries \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mfloat\u001b[39m(x) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m data)\n\u001b[1;32m 17\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_entries) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m---> 18\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma vector must have at least one entry\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mValueError\u001b[0m: a vector must have at least one entry" "\u001b[0;31mValueError\u001b[0m: a vector must have at least one entry"
] ]
} }
@ -1589,8 +1590,8 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-46-87c8bd55bdc1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mMatrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[45], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mMatrix\u001b[49m\u001b[43m(\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;32m<ipython-input-37-2c8575833cd9>\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"rows must have the same number of entries\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"a matrix must have at least one entry\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__repr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[36], line 9\u001b[0m, in \u001b[0;36mMatrix.__init__\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrows must have the same number of entries\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_entries) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m----> 9\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma matrix must have at least one entry\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mValueError\u001b[0m: a matrix must have at least one entry" "\u001b[0;31mValueError\u001b[0m: a matrix must have at least one entry"
] ]
} }
@ -1615,8 +1616,8 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-47-359f87edecdf>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mMatrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[46], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mMatrix\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m4\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;32m<ipython-input-37-2c8575833cd9>\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mrow\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrow\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"rows must have the same number of entries\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"a matrix must have at least one entry\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[36], line 7\u001b[0m, in \u001b[0;36mMatrix.__init__\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m row \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_entries[\u001b[38;5;241m1\u001b[39m:]:\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(row) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_entries[\u001b[38;5;241m0\u001b[39m]):\n\u001b[0;32m----> 7\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrows must have the same number of entries\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_entries) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma matrix must have at least one entry\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mValueError\u001b[0m: rows must have the same number of entries" "\u001b[0;31mValueError\u001b[0m: rows must have the same number of entries"
] ]
} }
@ -2083,13 +2084,13 @@
"outputs": [ "outputs": [
{ {
"ename": "AttributeError", "ename": "AttributeError",
"evalue": "can't set attribute", "evalue": "property 'n_rows' of 'Matrix' object has no setter",
"output_type": "error", "output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-62-f4cc4767ae11>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_rows\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[61], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mn_rows\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m3\u001b[39m\n",
"\u001b[0;31mAttributeError\u001b[0m: can't set attribute" "\u001b[0;31mAttributeError\u001b[0m: property 'n_rows' of 'Matrix' object has no setter"
] ]
} }
], ],
@ -2114,7 +2115,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.6" "version": "3.12.2"
}, },
"livereveal": { "livereveal": {
"auto_select": "code", "auto_select": "code",

View file

@ -1476,7 +1476,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.6" "version": "3.12.2"
}, },
"toc": { "toc": {
"base_numbering": 1, "base_numbering": 1,

View file

@ -346,7 +346,7 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-10-ac550dc2349d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m99\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[10], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mv\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m99\u001b[39m\n",
"\u001b[0;31mTypeError\u001b[0m: 'Vector' object does not support item assignment" "\u001b[0;31mTypeError\u001b[0m: 'Vector' object does not support item assignment"
] ]
} }
@ -1200,7 +1200,7 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-37-21b8354a80f8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtranspose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtranspose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[37], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtranspose\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtranspose\u001b[49m()\n",
"\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'transpose'" "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'transpose'"
] ]
} }
@ -1951,7 +1951,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.6" "version": "3.12.2"
}, },
"livereveal": { "livereveal": {
"auto_select": "code", "auto_select": "code",

View file

@ -415,8 +415,8 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-14-625d8ddab141>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mas_vector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[14], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mas_vector\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;32m<ipython-input-2-3a6f1abfe70b>\u001b[0m in \u001b[0;36mas_vector\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mas_vector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_rows\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_cols\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 24\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"one dimension (m or n) must be 1\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 25\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mVector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[2], line 24\u001b[0m, in \u001b[0;36mMatrix.as_vector\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mas_vector\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 23\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mn_rows \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mn_cols \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m):\n\u001b[0;32m---> 24\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mone dimension (m or n) must be 1\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 25\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m Vector(x \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m)\n",
"\u001b[0;31mRuntimeError\u001b[0m: one dimension (m or n) must be 1" "\u001b[0;31mRuntimeError\u001b[0m: one dimension (m or n) must be 1"
] ]
} }
@ -889,8 +889,8 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-27-21fab2d5f12e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mv\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mw\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[27], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mw\u001b[49m\n",
"\u001b[0;32m<ipython-input-21-e7b5dd8e219a>\u001b[0m in \u001b[0;36m__mul__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# dot product\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"vectors must be of the same length\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 48\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0my\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumbers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# scalar multiplication\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[21], line 47\u001b[0m, in \u001b[0;36mVector.__mul__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, Vector): \u001b[38;5;66;03m# dot product\u001b[39;00m\n\u001b[1;32m 46\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mlen\u001b[39m(other):\n\u001b[0;32m---> 47\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvectors must be of the same length\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28msum\u001b[39m(x \u001b[38;5;241m*\u001b[39m y \u001b[38;5;28;01mfor\u001b[39;00m (x, y) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(\u001b[38;5;28mself\u001b[39m, other))\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, numbers\u001b[38;5;241m.\u001b[39mNumber): \u001b[38;5;66;03m# scalar multiplication\u001b[39;00m\n",
"\u001b[0;31mValueError\u001b[0m: vectors must be of the same length" "\u001b[0;31mValueError\u001b[0m: vectors must be of the same length"
] ]
} }
@ -1009,8 +1009,8 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-31-490ee3f2b9e8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mv\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mw\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[31], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mw\u001b[49m\n",
"\u001b[0;32m<ipython-input-21-e7b5dd8e219a>\u001b[0m in \u001b[0;36m__add__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# vector addition\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 20\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"vectors must be of the same length\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 21\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mVector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0my\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumbers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# broadcasting addition\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[21], line 20\u001b[0m, in \u001b[0;36mVector.__add__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, Vector): \u001b[38;5;66;03m# vector addition\u001b[39;00m\n\u001b[1;32m 19\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mlen\u001b[39m(other):\n\u001b[0;32m---> 20\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvectors must be of the same length\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 21\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m Vector(x \u001b[38;5;241m+\u001b[39m y \u001b[38;5;28;01mfor\u001b[39;00m (x, y) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(\u001b[38;5;28mself\u001b[39m, other))\n\u001b[1;32m 22\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, numbers\u001b[38;5;241m.\u001b[39mNumber): \u001b[38;5;66;03m# broadcasting addition\u001b[39;00m\n",
"\u001b[0;31mValueError\u001b[0m: vectors must be of the same length" "\u001b[0;31mValueError\u001b[0m: vectors must be of the same length"
] ]
} }
@ -1098,6 +1098,7 @@
" src=\"https://www.youtube.com/embed/OMA2Mwo0aZg\"\n", " src=\"https://www.youtube.com/embed/OMA2Mwo0aZg\"\n",
" frameborder=\"0\"\n", " frameborder=\"0\"\n",
" allowfullscreen\n", " allowfullscreen\n",
" \n",
" ></iframe>\n", " ></iframe>\n",
" " " "
], ],
@ -1404,9 +1405,9 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-41-b57a49d097c9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mm\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[41], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mm\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mn\u001b[49m\n",
"\u001b[0;32m<ipython-input-35-def82d7b791b>\u001b[0m in \u001b[0;36m__mul__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_matrix_multiply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mas_matrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mas_vector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 73\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 74\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_matrix_multiply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 75\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mNotImplemented\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[35], line 74\u001b[0m, in \u001b[0;36mMatrix.__mul__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_matrix_multiply(other\u001b[38;5;241m.\u001b[39mas_matrix())\u001b[38;5;241m.\u001b[39mas_vector()\n\u001b[1;32m 73\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, Matrix):\n\u001b[0;32m---> 74\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_matrix_multiply\u001b[49m\u001b[43m(\u001b[49m\u001b[43mother\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 75\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mNotImplemented\u001b[39m\n",
"\u001b[0;32m<ipython-input-35-def82d7b791b>\u001b[0m in \u001b[0;36m_matrix_multiply\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_matrix_multiply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_cols\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_rows\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 65\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"matrices must have compatible dimensions\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 66\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mMatrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrv\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mcv\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mcv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcols\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mrv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrows\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[35], line 65\u001b[0m, in \u001b[0;36mMatrix._matrix_multiply\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_matrix_multiply\u001b[39m(\u001b[38;5;28mself\u001b[39m, other):\n\u001b[1;32m 64\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mn_cols \u001b[38;5;241m!=\u001b[39m other\u001b[38;5;241m.\u001b[39mn_rows:\n\u001b[0;32m---> 65\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmatrices must have compatible dimensions\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 66\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m Matrix((rv \u001b[38;5;241m*\u001b[39m cv \u001b[38;5;28;01mfor\u001b[39;00m cv \u001b[38;5;129;01min\u001b[39;00m other\u001b[38;5;241m.\u001b[39mcols()) \u001b[38;5;28;01mfor\u001b[39;00m rv \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrows())\n",
"\u001b[0;31mValueError\u001b[0m: matrices must have compatible dimensions" "\u001b[0;31mValueError\u001b[0m: matrices must have compatible dimensions"
] ]
} }
@ -1514,9 +1515,9 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-45-9faf2ee0ae54>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mv\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[45], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mn\u001b[49m\n",
"\u001b[0;32m<ipython-input-35-def82d7b791b>\u001b[0m in \u001b[0;36m__rmul__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mVector\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 81\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mas_matrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcolumn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_matrix_multiply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mas_vector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 82\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mNotImplemented\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[35], line 81\u001b[0m, in \u001b[0;36mMatrix.__rmul__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m \u001b[38;5;241m*\u001b[39m other\n\u001b[1;32m 80\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, Vector):\n\u001b[0;32m---> 81\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mother\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mas_matrix\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcolumn\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_matrix_multiply\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mas_vector()\n\u001b[1;32m 82\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mNotImplemented\u001b[39m\n",
"\u001b[0;32m<ipython-input-35-def82d7b791b>\u001b[0m in \u001b[0;36m_matrix_multiply\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_matrix_multiply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_cols\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_rows\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 65\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"matrices must have compatible dimensions\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 66\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mMatrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrv\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mcv\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mcv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcols\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mrv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrows\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[35], line 65\u001b[0m, in \u001b[0;36mMatrix._matrix_multiply\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_matrix_multiply\u001b[39m(\u001b[38;5;28mself\u001b[39m, other):\n\u001b[1;32m 64\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mn_cols \u001b[38;5;241m!=\u001b[39m other\u001b[38;5;241m.\u001b[39mn_rows:\n\u001b[0;32m---> 65\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmatrices must have compatible dimensions\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 66\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m Matrix((rv \u001b[38;5;241m*\u001b[39m cv \u001b[38;5;28;01mfor\u001b[39;00m cv \u001b[38;5;129;01min\u001b[39;00m other\u001b[38;5;241m.\u001b[39mcols()) \u001b[38;5;28;01mfor\u001b[39;00m rv \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrows())\n",
"\u001b[0;31mValueError\u001b[0m: matrices must have compatible dimensions" "\u001b[0;31mValueError\u001b[0m: matrices must have compatible dimensions"
] ]
} }
@ -1611,9 +1612,9 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-48-356d02c93f11>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mm\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mv\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[48], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mm\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\n",
"\u001b[0;32m<ipython-input-21-12852bd26164>\u001b[0m in \u001b[0;36m__radd__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__radd__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 27\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 28\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__sub__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[21], line 27\u001b[0m, in \u001b[0;36mVector.__radd__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__radd__\u001b[39m(\u001b[38;5;28mself\u001b[39m, other):\n\u001b[0;32m---> 27\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mother\u001b[49m\n",
"\u001b[0;32m<ipython-input-35-f4e0bb37caf6>\u001b[0m in \u001b[0;36m__radd__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 40\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__radd__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mVector\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 42\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"vectors and matrices cannot be added\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 43\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[35], line 42\u001b[0m, in \u001b[0;36mMatrix.__radd__\u001b[0;34m(self, other)\u001b[0m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__radd__\u001b[39m(\u001b[38;5;28mself\u001b[39m, other):\n\u001b[1;32m 41\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(other, Vector):\n\u001b[0;32m---> 42\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvectors and matrices cannot be added\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 43\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m \u001b[38;5;241m+\u001b[39m other\n",
"\u001b[0;31mTypeError\u001b[0m: vectors and matrices cannot be added" "\u001b[0;31mTypeError\u001b[0m: vectors and matrices cannot be added"
] ]
} }
@ -1933,7 +1934,7 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-59-c01df863c5f8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m-\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[59], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;241;43m-\u001b[39;49m\u001b[43mv\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: bad operand type for unary -: 'Vector'" "\u001b[0;31mTypeError\u001b[0m: bad operand type for unary -: 'Vector'"
] ]
} }
@ -1969,7 +1970,7 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-60-09d4e6f30397>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[60], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mabs\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mv\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: bad operand type for abs(): 'Vector'" "\u001b[0;31mTypeError\u001b[0m: bad operand type for abs(): 'Vector'"
] ]
} }
@ -2353,8 +2354,8 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-75-8369cec552f3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[75], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mfloat\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mv\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;32m<ipython-input-63-67b90fc89e7c>\u001b[0m in \u001b[0;36m__float__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__float__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 31\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"vector must have exactly one entry to become a scalar\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 32\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "Cell \u001b[0;32mIn[63], line 31\u001b[0m, in \u001b[0;36mVector.__float__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__float__\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 30\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m---> 31\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvector must have exactly one entry to become a scalar\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 32\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_entries[\u001b[38;5;241m0\u001b[39m]\n",
"\u001b[0;31mRuntimeError\u001b[0m: vector must have exactly one entry to become a scalar" "\u001b[0;31mRuntimeError\u001b[0m: vector must have exactly one entry to become a scalar"
] ]
} }
@ -2380,7 +2381,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.6" "version": "3.12.2"
}, },
"livereveal": { "livereveal": {
"auto_select": "code", "auto_select": "code",

View file

@ -74,7 +74,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"/home/webartifex/repos/intro-to-python/11_classes\n" "/home/alexander/Repositories/intro-to-python/11_classes\n"
] ]
} }
], ],
@ -106,8 +106,8 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"00_content.ipynb 02_content.ipynb 04_content.ipynb\n", "00_content.ipynb 02_content.ipynb 04_content.ipynb\t06_review.ipynb\n",
"01_exercises.ipynb 03_content.ipynb sample_package\n" "01_exercises.ipynb 03_content.ipynb 05_summary.ipynb\tsample_package\n"
] ]
} }
], ],
@ -202,7 +202,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"<module 'sample_package' from '/home/webartifex/repos/intro-to-python/11_classes/sample_package/__init__.py'>" "<module 'sample_package' from '/home/alexander/Repositories/intro-to-python/11_classes/sample_package/__init__.py'>"
] ]
}, },
"execution_count": 5, "execution_count": 5,
@ -324,9 +324,9 @@
" - vector: defines the Vector class\n", " - vector: defines the Vector class\n",
" - utils: defines the norm() function that is shared by Matrix and Vector\n", " - utils: defines the norm() function that is shared by Matrix and Vector\n",
" and package-wide constants\n", " and package-wide constants\n",
" \n", "\n",
" The classes implement arithmetic operations involving vectors and matrices.\n", " The classes implement arithmetic operations involving vectors and matrices.\n",
" \n", "\n",
" See the docstrings in the modules and classes for further info.\n", " See the docstrings in the modules and classes for further info.\n",
"\n", "\n",
"PACKAGE CONTENTS\n", "PACKAGE CONTENTS\n",
@ -338,14 +338,14 @@
" builtins.object\n", " builtins.object\n",
" sample_package.matrix.Matrix\n", " sample_package.matrix.Matrix\n",
" sample_package.vector.Vector\n", " sample_package.vector.Vector\n",
" \n", "\n",
" class Matrix(builtins.object)\n", " class Matrix(builtins.object)\n",
" | Matrix(data)\n", " | Matrix(data)\n",
" | \n", " |\n",
" | An m-by-n-dimensional matrix from linear algebra.\n", " | An m-by-n-dimensional matrix from linear algebra.\n",
" | \n", " |\n",
" | All entries are converted to floats, or whatever is set in the typing attribute.\n", " | All entries are converted to floats, or whatever is set in the typing attribute.\n",
" | \n", " |\n",
" | Attributes:\n", " | Attributes:\n",
" | storage (callable): data type used to store the entries internally;\n", " | storage (callable): data type used to store the entries internally;\n",
" | defaults to tuple\n", " | defaults to tuple\n",
@ -354,63 +354,63 @@
" | vector_cls (vector.Vector): a reference to the Vector class to work with\n", " | vector_cls (vector.Vector): a reference to the Vector class to work with\n",
" | zero_threshold (float): max. tolerance when comparing an entry to zero;\n", " | zero_threshold (float): max. tolerance when comparing an entry to zero;\n",
" | defaults to 1e-12\n", " | defaults to 1e-12\n",
" | \n", " |\n",
" | Methods defined here:\n", " | Methods defined here:\n",
" | \n", " |\n",
" | __abs__(self)\n", " | __abs__(self)\n",
" | The Frobenius norm of a Matrix.\n", " | The Frobenius norm of a Matrix.\n",
" | \n", " |\n",
" | __add__(self, other)\n", " | __add__(self, other)\n",
" | Handle `self + other` and `other + self`.\n", " | Handle `self + other` and `other + self`.\n",
" | \n", " |\n",
" | This may be either matrix addition or broadcasting addition.\n", " | This may be either matrix addition or broadcasting addition.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Matrix([(1, 2), (3, 4)]) + Matrix([(2, 3), (4, 5)])\n", " | >>> Matrix([(1, 2), (3, 4)]) + Matrix([(2, 3), (4, 5)])\n",
" | Matrix(((3.0, 5.0,), (7.0, 9.0,)))\n", " | Matrix(((3.0, 5.0,), (7.0, 9.0,)))\n",
" | \n", " |\n",
" | >>> Matrix([(1, 2), (3, 4)]) + 5\n", " | >>> Matrix([(1, 2), (3, 4)]) + 5\n",
" | Matrix(((6.0, 7.0,), (8.0, 9.0,)))\n", " | Matrix(((6.0, 7.0,), (8.0, 9.0,)))\n",
" | \n", " |\n",
" | >>> 10 + Matrix([(1, 2), (3, 4)])\n", " | >>> 10 + Matrix([(1, 2), (3, 4)])\n",
" | Matrix(((11.0, 12.0,), (13.0, 14.0,)))\n", " | Matrix(((11.0, 12.0,), (13.0, 14.0,)))\n",
" | \n", " |\n",
" | __bool__(self)\n", " | __bool__(self)\n",
" | A Matrix is truthy if its Frobenius norm is strictly positive.\n", " | A Matrix is truthy if its Frobenius norm is strictly positive.\n",
" | \n", " |\n",
" | __eq__(self, other)\n", " | __eq__(self, other)\n",
" | Handle `self == other`.\n", " | Handle `self == other`.\n",
" | \n", " |\n",
" | Compare two Matrix instances for equality.\n", " | Compare two Matrix instances for equality.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Matrix([(1, 2), (3, 4)]) == Matrix([(1, 2), (3, 4)])\n", " | >>> Matrix([(1, 2), (3, 4)]) == Matrix([(1, 2), (3, 4)])\n",
" | True\n", " | True\n",
" | \n", " |\n",
" | >>> Matrix([(1, 2), (3, 4)]) == Matrix([(5, 6), (7, 8)])\n", " | >>> Matrix([(1, 2), (3, 4)]) == Matrix([(5, 6), (7, 8)])\n",
" | False\n", " | False\n",
" | \n", " |\n",
" | __float__(self)\n", " | __float__(self)\n",
" | Cast a Matrix as a scalar.\n", " | Cast a Matrix as a scalar.\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | scalar (float)\n", " | scalar (float)\n",
" | \n", " |\n",
" | Raises:\n", " | Raises:\n",
" | RuntimeError: if the Matrix has more than one entry\n", " | RuntimeError: if the Matrix has more than one entry\n",
" | \n", " |\n",
" | __getitem__(self, index)\n", " | __getitem__(self, index)\n",
" | Obtain an individual entry of a Matrix.\n", " | Obtain an individual entry of a Matrix.\n",
" | \n", " |\n",
" | Args:\n", " | Args:\n",
" | index (int / tuple of int's): if index is an integer,\n", " | index (int / tuple of int's): if index is an integer,\n",
" | the Matrix is viewed as a sequence in row-major order;\n", " | the Matrix is viewed as a sequence in row-major order;\n",
" | if index is a tuple of integers, the first one refers to\n", " | if index is a tuple of integers, the first one refers to\n",
" | the row and the second one to the column of the entry\n", " | the row and the second one to the column of the entry\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | entry (Matrix.typing)\n", " | entry (Matrix.typing)\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> m = Matrix([(1, 2), (3, 4)])\n", " | >>> m = Matrix([(1, 2), (3, 4)])\n",
" | >>> m[0]\n", " | >>> m[0]\n",
@ -419,226 +419,228 @@
" | 4.0\n", " | 4.0\n",
" | >>> m[0, 1]\n", " | >>> m[0, 1]\n",
" | 2.0\n", " | 2.0\n",
" | \n", " |\n",
" | __init__(self, data)\n", " | __init__(self, data)\n",
" | Create a new matrix.\n", " | Create a new matrix.\n",
" | \n", " |\n",
" | Args:\n", " | Args:\n",
" | data (sequence of sequences): the matrix's entries;\n", " | data (sequence of sequences): the matrix's entries;\n",
" | viewed as a sequence of the matrix's rows (i.e., row-major order);\n", " | viewed as a sequence of the matrix's rows (i.e., row-major order);\n",
" | use the .from_columns() class method if the data come as a sequence\n", " | use the .from_columns() class method if the data come as a sequence\n",
" | of the matrix's columns (i.e., column-major order)\n", " | of the matrix's columns (i.e., column-major order)\n",
" | \n", " |\n",
" | Raises:\n", " | Raises:\n",
" | ValueError:\n", " | ValueError:\n",
" | - if no entries are provided\n", " | - if no entries are provided\n",
" | - if the number of columns is inconsistent across the rows\n", " | - if the number of columns is inconsistent across the rows\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Matrix([(1, 2), (3, 4)])\n", " | >>> Matrix([(1, 2), (3, 4)])\n",
" | Matrix(((1.0, 2.0,), (3.0, 4.0,)))\n", " | Matrix(((1.0, 2.0,), (3.0, 4.0,)))\n",
" | \n", " |\n",
" | __iter__(self)\n", " | __iter__(self)\n",
" | Loop over a Matrix's entries.\n", " | Loop over a Matrix's entries.\n",
" | \n", " |\n",
" | See .entries() for more customization options.\n", " | See .entries() for more customization options.\n",
" | \n", " |\n",
" | __len__(self)\n", " | __len__(self)\n",
" | Number of entries in a Matrix.\n", " | Number of entries in a Matrix.\n",
" | \n", " |\n",
" | __mul__(self, other)\n", " | __mul__(self, other)\n",
" | Handle `self * other` and `other * self`.\n", " | Handle `self * other` and `other * self`.\n",
" | \n", " |\n",
" | This may be either scalar multiplication, matrix-vector multiplication,\n", " | This may be either scalar multiplication, matrix-vector multiplication,\n",
" | vector-matrix multiplication, or matrix-matrix multiplication.\n", " | vector-matrix multiplication, or matrix-matrix multiplication.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Matrix([(1, 2), (3, 4)]) * Matrix([(1, 2), (3, 4)])\n", " | >>> Matrix([(1, 2), (3, 4)]) * Matrix([(1, 2), (3, 4)])\n",
" | Matrix(((7.0, 10.0,), (15.0, 22.0,)))\n", " | Matrix(((7.0, 10.0,), (15.0, 22.0,)))\n",
" | \n", " |\n",
" | >>> 2 * Matrix([(1, 2), (3, 4)])\n", " | >>> 2 * Matrix([(1, 2), (3, 4)])\n",
" | Matrix(((2.0, 4.0,), (6.0, 8.0,)))\n", " | Matrix(((2.0, 4.0,), (6.0, 8.0,)))\n",
" | \n", " |\n",
" | >>> Matrix([(1, 2), (3, 4)]) * 3\n", " | >>> Matrix([(1, 2), (3, 4)]) * 3\n",
" | Matrix(((3.0, 6.0,), (9.0, 12.0,)))\n", " | Matrix(((3.0, 6.0,), (9.0, 12.0,)))\n",
" | \n", " |\n",
" | Matrix-vector and vector-matrix multiplication are not commutative.\n", " | Matrix-vector and vector-matrix multiplication are not commutative.\n",
" | \n", " |\n",
" | >>> from sample_package import Vector\n", " | >>> from sample_package import Vector\n",
" | \n", " |\n",
" | >>> Matrix([(1, 2), (3, 4)]) * Vector([5, 6])\n", " | >>> Matrix([(1, 2), (3, 4)]) * Vector([5, 6])\n",
" | Vector((17.0, 39.0))\n", " | Vector((17.0, 39.0))\n",
" | \n", " |\n",
" | >>> Vector([5, 6]) * Matrix([(1, 2), (3, 4)])\n", " | >>> Vector([5, 6]) * Matrix([(1, 2), (3, 4)])\n",
" | Vector((23.0, 34.0))\n", " | Vector((23.0, 34.0))\n",
" | \n", " |\n",
" | __neg__(self)\n", " | __neg__(self)\n",
" | Handle `-self`.\n", " | Handle `-self`.\n",
" | \n", " |\n",
" | Negate all entries of a Matrix.\n", " | Negate all entries of a Matrix.\n",
" | \n", " |\n",
" | __pos__(self)\n", " | __pos__(self)\n",
" | Handle `+self`.\n", " | Handle `+self`.\n",
" | \n", " |\n",
" | This is simply an identity operator returning the Matrix itself.\n", " | This is simply an identity operator returning the Matrix itself.\n",
" | \n", " |\n",
" | __radd__(self, other)\n", " | __radd__(self, other)\n",
" | See docstring for .__add__().\n", " | See docstring for .__add__().\n",
" | \n", " |\n",
" | __repr__(self)\n", " | __repr__(self)\n",
" | Text representation of a Matrix.\n", " | Text representation of a Matrix.\n",
" | \n", " |\n",
" | __reversed__(self)\n", " | __reversed__(self)\n",
" | Loop over a Matrix's entries in reverse order.\n", " | Loop over a Matrix's entries in reverse order.\n",
" | \n", " |\n",
" | See .entries() for more customization options.\n", " | See .entries() for more customization options.\n",
" | \n", " |\n",
" | __rmul__(self, other)\n", " | __rmul__(self, other)\n",
" | See docstring for .__mul__().\n", " | See docstring for .__mul__().\n",
" | \n", " |\n",
" | __rsub__(self, other)\n", " | __rsub__(self, other)\n",
" | See docstring for .__sub__().\n", " | See docstring for .__sub__().\n",
" | \n", " |\n",
" | __str__(self)\n", " | __str__(self)\n",
" | Human-readable text representation of a Matrix.\n", " | Human-readable text representation of a Matrix.\n",
" | \n", " |\n",
" | __sub__(self, other)\n", " | __sub__(self, other)\n",
" | Handle `self - other` and `other - self`.\n", " | Handle `self - other` and `other - self`.\n",
" | \n", " |\n",
" | This may be either matrix subtraction or broadcasting subtraction.\n", " | This may be either matrix subtraction or broadcasting subtraction.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Matrix([(2, 3), (4, 5)]) - Matrix([(1, 2), (3, 4)])\n", " | >>> Matrix([(2, 3), (4, 5)]) - Matrix([(1, 2), (3, 4)])\n",
" | Matrix(((1.0, 1.0,), (1.0, 1.0,)))\n", " | Matrix(((1.0, 1.0,), (1.0, 1.0,)))\n",
" | \n", " |\n",
" | >>> Matrix([(1, 2), (3, 4)]) - 1\n", " | >>> Matrix([(1, 2), (3, 4)]) - 1\n",
" | Matrix(((0.0, 1.0,), (2.0, 3.0,)))\n", " | Matrix(((0.0, 1.0,), (2.0, 3.0,)))\n",
" | \n", " |\n",
" | >>> 10 - Matrix([(1, 2), (3, 4)])\n", " | >>> 10 - Matrix([(1, 2), (3, 4)])\n",
" | Matrix(((9.0, 8.0,), (7.0, 6.0,)))\n", " | Matrix(((9.0, 8.0,), (7.0, 6.0,)))\n",
" | \n", " |\n",
" | __truediv__(self, other)\n", " | __truediv__(self, other)\n",
" | Handle `self / other`.\n", " | Handle `self / other`.\n",
" | \n", " |\n",
" | Divide a Matrix by a scalar.\n", " | Divide a Matrix by a scalar.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Matrix([(1, 2), (3, 4)]) / 4\n", " | >>> Matrix([(1, 2), (3, 4)]) / 4\n",
" | Matrix(((0.25, 0.5,), (0.75, 1.0,)))\n", " | Matrix(((0.25, 0.5,), (0.75, 1.0,)))\n",
" | \n", " |\n",
" | as_vector(self)\n", " | as_vector(self)\n",
" | Get a Vector representation of a Matrix.\n", " | Get a Vector representation of a Matrix.\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | vector (vector.Vector)\n", " | vector (vector.Vector)\n",
" | \n", " |\n",
" | Raises:\n", " | Raises:\n",
" | RuntimeError: if one of the two dimensions, .n_rows or .n_cols, is not 1\n", " | RuntimeError: if one of the two dimensions, .n_rows or .n_cols, is not 1\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Matrix([(1, 2, 3)]).as_vector()\n", " | >>> Matrix([(1, 2, 3)]).as_vector()\n",
" | Vector((1.0, 2.0, 3.0))\n", " | Vector((1.0, 2.0, 3.0))\n",
" | \n", " |\n",
" | cols(self)\n", " | cols(self)\n",
" | Loop over a Matrix's columns.\n", " | Loop over a Matrix's columns.\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | columns (generator): produces a Matrix's columns as Vectors\n", " | columns (generator): produces a Matrix's columns as Vectors\n",
" | \n", " |\n",
" | entries(self, *, reverse=False, row_major=True)\n", " | entries(self, *, reverse=False, row_major=True)\n",
" | Loop over a Matrix's entries.\n", " | Loop over a Matrix's entries.\n",
" | \n", " |\n",
" | Args:\n", " | Args:\n",
" | reverse (bool): flag to loop backwards; defaults to False\n", " | reverse (bool): flag to loop backwards; defaults to False\n",
" | row_major (bool): flag to loop in row-major order; defaults to True\n", " | row_major (bool): flag to loop in row-major order; defaults to True\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | entries (generator): produces a Matrix's entries\n", " | entries (generator): produces a Matrix's entries\n",
" | \n", " |\n",
" | rows(self)\n", " | rows(self)\n",
" | Loop over a Matrix's rows.\n", " | Loop over a Matrix's rows.\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | rows (generator): produces a Matrix's rows as Vectors\n", " | rows (generator): produces a Matrix's rows as Vectors\n",
" | \n", " |\n",
" | transpose(self)\n", " | transpose(self)\n",
" | Switch the rows and columns of a Matrix.\n", " | Switch the rows and columns of a Matrix.\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | matrix (Matrix)\n", " | matrix (Matrix)\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> m = Matrix([(1, 2), (3, 4)])\n", " | >>> m = Matrix([(1, 2), (3, 4)])\n",
" | >>> m\n", " | >>> m\n",
" | Matrix(((1.0, 2.0,), (3.0, 4.0,)))\n", " | Matrix(((1.0, 2.0,), (3.0, 4.0,)))\n",
" | >>> m.transpose()\n", " | >>> m.transpose()\n",
" | Matrix(((1.0, 3.0,), (2.0, 4.0,)))\n", " | Matrix(((1.0, 3.0,), (2.0, 4.0,)))\n",
" | \n", " |\n",
" | ----------------------------------------------------------------------\n", " | ----------------------------------------------------------------------\n",
" | Class methods defined here:\n", " | Class methods defined here:\n",
" | \n", " |\n",
" | from_columns(data) from builtins.type\n", " | from_columns(data) from builtins.type\n",
" | Create a new matrix.\n", " | Create a new matrix.\n",
" | \n", " |\n",
" | This is an alternative constructor for data provided in column-major order.\n", " | This is an alternative constructor for data provided in column-major order.\n",
" | \n", " |\n",
" | Args:\n", " | Args:\n",
" | data (sequence of sequences): the matrix's entries;\n", " | data (sequence of sequences): the matrix's entries;\n",
" | viewed as a sequence of the matrix's columns (i.e., column-major order);\n", " | viewed as a sequence of the matrix's columns (i.e., column-major order);\n",
" | use the normal constructor method if the data come as a sequence\n", " | use the normal constructor method if the data come as a sequence\n",
" | of the matrix's rows (i.e., row-major order)\n", " | of the matrix's rows (i.e., row-major order)\n",
" | \n", " |\n",
" | Raises:\n", " | Raises:\n",
" | ValueError:\n", " | ValueError:\n",
" | - if no entries are provided\n", " | - if no entries are provided\n",
" | - if the number of rows is inconsistent across the columns\n", " | - if the number of rows is inconsistent across the columns\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Matrix.from_columns([(1, 2), (3, 4)])\n", " | >>> Matrix.from_columns([(1, 2), (3, 4)])\n",
" | Matrix(((1.0, 3.0,), (2.0, 4.0,)))\n", " | Matrix(((1.0, 3.0,), (2.0, 4.0,)))\n",
" | \n", " |\n",
" | from_rows(data) from builtins.type\n", " | from_rows(data) from builtins.type\n",
" | See docstring for .__init__().\n", " | See docstring for .__init__().\n",
" | \n", " |\n",
" | ----------------------------------------------------------------------\n", " | ----------------------------------------------------------------------\n",
" | Readonly properties defined here:\n", " | Readonly properties defined here:\n",
" | \n", " |\n",
" | n_cols\n", " | n_cols\n",
" | Number of columns in a Matrix.\n", " | Number of columns in a Matrix.\n",
" | \n", " |\n",
" | n_rows\n", " | n_rows\n",
" | Number of rows in a Matrix.\n", " | Number of rows in a Matrix.\n",
" | \n", " |\n",
" | ----------------------------------------------------------------------\n", " | ----------------------------------------------------------------------\n",
" | Data descriptors defined here:\n", " | Data descriptors defined here:\n",
" | \n", " |\n",
" | __dict__\n", " | __dict__\n",
" | dictionary for instance variables (if defined)\n", " | dictionary for instance variables\n",
" | \n", " |\n",
" | __weakref__\n", " | __weakref__\n",
" | list of weak references to the object (if defined)\n", " | list of weak references to the object\n",
" | \n", " |\n",
" | ----------------------------------------------------------------------\n", " | ----------------------------------------------------------------------\n",
" | Data and other attributes defined here:\n", " | Data and other attributes defined here:\n",
" | \n", " |\n",
" | __hash__ = None\n", " | __hash__ = None\n",
" | \n", " |\n",
" | storage = <class 'tuple'>\n", " | storage = <class 'tuple'>\n",
" | Built-in immutable sequence.\n", " | Built-in immutable sequence.\n",
" | \n", " |\n",
" | If no argument is given, the constructor returns an empty tuple.\n", " | If no argument is given, the constructor returns an empty tuple.\n",
" | If iterable is specified the tuple is initialized from iterable's items.\n", " | If iterable is specified the tuple is initialized from iterable's items.\n",
" | \n", " |\n",
" | If the argument is a tuple, the return value is the same object.\n", " | If the argument is a tuple, the return value is the same object.\n",
" | \n", " |\n",
" |\n",
" | typing = <class 'float'>\n", " | typing = <class 'float'>\n",
" | Convert a string or number to a floating point number, if possible.\n", " | Convert a string or number to a floating point number, if possible.\n",
" | \n", " |\n",
" |\n",
" | vector_cls = <class 'sample_package.vector.Vector'>\n", " | vector_cls = <class 'sample_package.vector.Vector'>\n",
" | A one-dimensional vector from linear algebra.\n", " | A one-dimensional vector from linear algebra.\n",
" | \n", " |\n",
" | All entries are converted to floats, or whatever is set in the typing attribute.\n", " | All entries are converted to floats, or whatever is set in the typing attribute.\n",
" | \n", " |\n",
" | Attributes:\n", " | Attributes:\n",
" | matrix_cls (matrix.Matrix): a reference to the Matrix class to work with\n", " | matrix_cls (matrix.Matrix): a reference to the Matrix class to work with\n",
" | storage (callable): data type used to store the entries internally;\n", " | storage (callable): data type used to store the entries internally;\n",
@ -647,16 +649,17 @@
" | defaults to float\n", " | defaults to float\n",
" | zero_threshold (float): max. tolerance when comparing an entry to zero;\n", " | zero_threshold (float): max. tolerance when comparing an entry to zero;\n",
" | defaults to 1e-12\n", " | defaults to 1e-12\n",
" | \n", " |\n",
" |\n",
" | zero_threshold = 1e-12\n", " | zero_threshold = 1e-12\n",
" \n", "\n",
" class Vector(builtins.object)\n", " class Vector(builtins.object)\n",
" | Vector(data)\n", " | Vector(data)\n",
" | \n", " |\n",
" | A one-dimensional vector from linear algebra.\n", " | A one-dimensional vector from linear algebra.\n",
" | \n", " |\n",
" | All entries are converted to floats, or whatever is set in the typing attribute.\n", " | All entries are converted to floats, or whatever is set in the typing attribute.\n",
" | \n", " |\n",
" | Attributes:\n", " | Attributes:\n",
" | matrix_cls (matrix.Matrix): a reference to the Matrix class to work with\n", " | matrix_cls (matrix.Matrix): a reference to the Matrix class to work with\n",
" | storage (callable): data type used to store the entries internally;\n", " | storage (callable): data type used to store the entries internally;\n",
@ -665,179 +668,179 @@
" | defaults to float\n", " | defaults to float\n",
" | zero_threshold (float): max. tolerance when comparing an entry to zero;\n", " | zero_threshold (float): max. tolerance when comparing an entry to zero;\n",
" | defaults to 1e-12\n", " | defaults to 1e-12\n",
" | \n", " |\n",
" | Methods defined here:\n", " | Methods defined here:\n",
" | \n", " |\n",
" | __abs__(self)\n", " | __abs__(self)\n",
" | The Euclidean norm of a vector.\n", " | The Euclidean norm of a vector.\n",
" | \n", " |\n",
" | __add__(self, other)\n", " | __add__(self, other)\n",
" | Handle `self + other` and `other + self`.\n", " | Handle `self + other` and `other + self`.\n",
" | \n", " |\n",
" | This may be either vector addition or broadcasting addition.\n", " | This may be either vector addition or broadcasting addition.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Vector([1, 2, 3]) + Vector([2, 3, 4])\n", " | >>> Vector([1, 2, 3]) + Vector([2, 3, 4])\n",
" | Vector((3.0, 5.0, 7.0))\n", " | Vector((3.0, 5.0, 7.0))\n",
" | \n", " |\n",
" | >>> Vector([1, 2, 3]) + 4\n", " | >>> Vector([1, 2, 3]) + 4\n",
" | Vector((5.0, 6.0, 7.0))\n", " | Vector((5.0, 6.0, 7.0))\n",
" | \n", " |\n",
" | >>> 10 + Vector([1, 2, 3])\n", " | >>> 10 + Vector([1, 2, 3])\n",
" | Vector((11.0, 12.0, 13.0))\n", " | Vector((11.0, 12.0, 13.0))\n",
" | \n", " |\n",
" | __bool__(self)\n", " | __bool__(self)\n",
" | A Vector is truthy if its Euclidean norm is strictly positive.\n", " | A Vector is truthy if its Euclidean norm is strictly positive.\n",
" | \n", " |\n",
" | __eq__(self, other)\n", " | __eq__(self, other)\n",
" | Handle `self == other`.\n", " | Handle `self == other`.\n",
" | \n", " |\n",
" | Compare two Vectors for equality.\n", " | Compare two Vectors for equality.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Vector([1, 2, 3]) == Vector([1, 2, 3])\n", " | >>> Vector([1, 2, 3]) == Vector([1, 2, 3])\n",
" | True\n", " | True\n",
" | \n", " |\n",
" | >>> Vector([1, 2, 3]) == Vector([4, 5, 6])\n", " | >>> Vector([1, 2, 3]) == Vector([4, 5, 6])\n",
" | False\n", " | False\n",
" | \n", " |\n",
" | __float__(self)\n", " | __float__(self)\n",
" | Cast a Vector as a scalar.\n", " | Cast a Vector as a scalar.\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | scalar (float)\n", " | scalar (float)\n",
" | \n", " |\n",
" | Raises:\n", " | Raises:\n",
" | RuntimeError: if the Vector has more than one entry\n", " | RuntimeError: if the Vector has more than one entry\n",
" | \n", " |\n",
" | __getitem__(self, index)\n", " | __getitem__(self, index)\n",
" | Obtain an individual entry of a Vector.\n", " | Obtain an individual entry of a Vector.\n",
" | \n", " |\n",
" | __init__(self, data)\n", " | __init__(self, data)\n",
" | Create a new vector.\n", " | Create a new vector.\n",
" | \n", " |\n",
" | Args:\n", " | Args:\n",
" | data (sequence): the vector's entries\n", " | data (sequence): the vector's entries\n",
" | \n", " |\n",
" | Raises:\n", " | Raises:\n",
" | ValueError: if no entries are provided\n", " | ValueError: if no entries are provided\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Vector([1, 2, 3])\n", " | >>> Vector([1, 2, 3])\n",
" | Vector((1.0, 2.0, 3.0))\n", " | Vector((1.0, 2.0, 3.0))\n",
" | \n", " |\n",
" | >>> Vector(range(3))\n", " | >>> Vector(range(3))\n",
" | Vector((0.0, 1.0, 2.0))\n", " | Vector((0.0, 1.0, 2.0))\n",
" | \n", " |\n",
" | __iter__(self)\n", " | __iter__(self)\n",
" | Loop over a Vector's entries.\n", " | Loop over a Vector's entries.\n",
" | \n", " |\n",
" | __len__(self)\n", " | __len__(self)\n",
" | Number of entries in a Vector.\n", " | Number of entries in a Vector.\n",
" | \n", " |\n",
" | __mul__(self, other)\n", " | __mul__(self, other)\n",
" | Handle `self * other` and `other * self`.\n", " | Handle `self * other` and `other * self`.\n",
" | \n", " |\n",
" | This may be either the dot product of two vectors or scalar multiplication.\n", " | This may be either the dot product of two vectors or scalar multiplication.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Vector([1, 2, 3]) * Vector([2, 3, 4])\n", " | >>> Vector([1, 2, 3]) * Vector([2, 3, 4])\n",
" | 20.0\n", " | 20.0\n",
" | \n", " |\n",
" | >>> 2 * Vector([1, 2, 3])\n", " | >>> 2 * Vector([1, 2, 3])\n",
" | Vector((2.0, 4.0, 6.0))\n", " | Vector((2.0, 4.0, 6.0))\n",
" | \n", " |\n",
" | >>> Vector([1, 2, 3]) * 3\n", " | >>> Vector([1, 2, 3]) * 3\n",
" | Vector((3.0, 6.0, 9.0))\n", " | Vector((3.0, 6.0, 9.0))\n",
" | \n", " |\n",
" | __neg__(self)\n", " | __neg__(self)\n",
" | Handle `-self`.\n", " | Handle `-self`.\n",
" | \n", " |\n",
" | Negate all entries of a Vector.\n", " | Negate all entries of a Vector.\n",
" | \n", " |\n",
" | __pos__(self)\n", " | __pos__(self)\n",
" | Handle `+self`.\n", " | Handle `+self`.\n",
" | \n", " |\n",
" | This is simply an identity operator returning the Vector itself.\n", " | This is simply an identity operator returning the Vector itself.\n",
" | \n", " |\n",
" | __radd__(self, other)\n", " | __radd__(self, other)\n",
" | See docstring for .__add__().\n", " | See docstring for .__add__().\n",
" | \n", " |\n",
" | __repr__(self)\n", " | __repr__(self)\n",
" | Text representation of a Vector.\n", " | Text representation of a Vector.\n",
" | \n", " |\n",
" | __reversed__(self)\n", " | __reversed__(self)\n",
" | Loop over a Vector's entries in reverse order.\n", " | Loop over a Vector's entries in reverse order.\n",
" | \n", " |\n",
" | __rmul__(self, other)\n", " | __rmul__(self, other)\n",
" | See docstring for .__mul__().\n", " | See docstring for .__mul__().\n",
" | \n", " |\n",
" | __rsub__(self, other)\n", " | __rsub__(self, other)\n",
" | See docstring for .__sub__().\n", " | See docstring for .__sub__().\n",
" | \n", " |\n",
" | __str__(self)\n", " | __str__(self)\n",
" | Human-readable text representation of a Vector.\n", " | Human-readable text representation of a Vector.\n",
" | \n", " |\n",
" | __sub__(self, other)\n", " | __sub__(self, other)\n",
" | Handle `self - other` and `other - self`.\n", " | Handle `self - other` and `other - self`.\n",
" | \n", " |\n",
" | This may be either vector subtraction or broadcasting subtraction.\n", " | This may be either vector subtraction or broadcasting subtraction.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Vector([7, 8, 9]) - Vector([1, 2, 3])\n", " | >>> Vector([7, 8, 9]) - Vector([1, 2, 3])\n",
" | Vector((6.0, 6.0, 6.0))\n", " | Vector((6.0, 6.0, 6.0))\n",
" | \n", " |\n",
" | >>> Vector([1, 2, 3]) - 1\n", " | >>> Vector([1, 2, 3]) - 1\n",
" | Vector((0.0, 1.0, 2.0))\n", " | Vector((0.0, 1.0, 2.0))\n",
" | \n", " |\n",
" | >>> 10 - Vector([1, 2, 3])\n", " | >>> 10 - Vector([1, 2, 3])\n",
" | Vector((9.0, 8.0, 7.0))\n", " | Vector((9.0, 8.0, 7.0))\n",
" | \n", " |\n",
" | __truediv__(self, other)\n", " | __truediv__(self, other)\n",
" | Handle `self / other`.\n", " | Handle `self / other`.\n",
" | \n", " |\n",
" | Divide a Vector by a scalar.\n", " | Divide a Vector by a scalar.\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> Vector([9, 6, 12]) / 3\n", " | >>> Vector([9, 6, 12]) / 3\n",
" | Vector((3.0, 2.0, 4.0))\n", " | Vector((3.0, 2.0, 4.0))\n",
" | \n", " |\n",
" | as_matrix(self, *, column=True)\n", " | as_matrix(self, *, column=True)\n",
" | Get a Matrix representation of a Vector.\n", " | Get a Matrix representation of a Vector.\n",
" | \n", " |\n",
" | Args:\n", " | Args:\n",
" | column (bool): if the vector is interpreted as a\n", " | column (bool): if the vector is interpreted as a\n",
" | column vector or a row vector; defaults to True\n", " | column vector or a row vector; defaults to True\n",
" | \n", " |\n",
" | Returns:\n", " | Returns:\n",
" | matrix (matrix.Matrix)\n", " | matrix (matrix.Matrix)\n",
" | \n", " |\n",
" | Example Usage:\n", " | Example Usage:\n",
" | >>> v = Vector([1, 2, 3])\n", " | >>> v = Vector([1, 2, 3])\n",
" | >>> v.as_matrix()\n", " | >>> v.as_matrix()\n",
" | Matrix(((1.0,), (2.0,), (3.0,)))\n", " | Matrix(((1.0,), (2.0,), (3.0,)))\n",
" | >>> v.as_matrix(column=False)\n", " | >>> v.as_matrix(column=False)\n",
" | Matrix(((1.0, 2.0, 3.0,)))\n", " | Matrix(((1.0, 2.0, 3.0,)))\n",
" | \n", " |\n",
" | ----------------------------------------------------------------------\n", " | ----------------------------------------------------------------------\n",
" | Data descriptors defined here:\n", " | Data descriptors defined here:\n",
" | \n", " |\n",
" | __dict__\n", " | __dict__\n",
" | dictionary for instance variables (if defined)\n", " | dictionary for instance variables\n",
" | \n", " |\n",
" | __weakref__\n", " | __weakref__\n",
" | list of weak references to the object (if defined)\n", " | list of weak references to the object\n",
" | \n", " |\n",
" | ----------------------------------------------------------------------\n", " | ----------------------------------------------------------------------\n",
" | Data and other attributes defined here:\n", " | Data and other attributes defined here:\n",
" | \n", " |\n",
" | __hash__ = None\n", " | __hash__ = None\n",
" | \n", " |\n",
" | matrix_cls = <class 'sample_package.matrix.Matrix'>\n", " | matrix_cls = <class 'sample_package.matrix.Matrix'>\n",
" | An m-by-n-dimensional matrix from linear algebra.\n", " | An m-by-n-dimensional matrix from linear algebra.\n",
" | \n", " |\n",
" | All entries are converted to floats, or whatever is set in the typing attribute.\n", " | All entries are converted to floats, or whatever is set in the typing attribute.\n",
" | \n", " |\n",
" | Attributes:\n", " | Attributes:\n",
" | storage (callable): data type used to store the entries internally;\n", " | storage (callable): data type used to store the entries internally;\n",
" | defaults to tuple\n", " | defaults to tuple\n",
@ -846,18 +849,21 @@
" | vector_cls (vector.Vector): a reference to the Vector class to work with\n", " | vector_cls (vector.Vector): a reference to the Vector class to work with\n",
" | zero_threshold (float): max. tolerance when comparing an entry to zero;\n", " | zero_threshold (float): max. tolerance when comparing an entry to zero;\n",
" | defaults to 1e-12\n", " | defaults to 1e-12\n",
" | \n", " |\n",
" |\n",
" | storage = <class 'tuple'>\n", " | storage = <class 'tuple'>\n",
" | Built-in immutable sequence.\n", " | Built-in immutable sequence.\n",
" | \n", " |\n",
" | If no argument is given, the constructor returns an empty tuple.\n", " | If no argument is given, the constructor returns an empty tuple.\n",
" | If iterable is specified the tuple is initialized from iterable's items.\n", " | If iterable is specified the tuple is initialized from iterable's items.\n",
" | \n", " |\n",
" | If the argument is a tuple, the return value is the same object.\n", " | If the argument is a tuple, the return value is the same object.\n",
" | \n", " |\n",
" |\n",
" | typing = <class 'float'>\n", " | typing = <class 'float'>\n",
" | Convert a string or number to a floating point number, if possible.\n", " | Convert a string or number to a floating point number, if possible.\n",
" | \n", " |\n",
" |\n",
" | zero_threshold = 1e-12\n", " | zero_threshold = 1e-12\n",
"\n", "\n",
"DATA\n", "DATA\n",
@ -870,7 +876,7 @@
" Alexander Hess\n", " Alexander Hess\n",
"\n", "\n",
"FILE\n", "FILE\n",
" /home/webartifex/repos/intro-to-python/11_classes/sample_package/__init__.py\n", " /home/alexander/Repositories/intro-to-python/11_classes/sample_package/__init__.py\n",
"\n", "\n",
"\n" "\n"
] ]
@ -1102,15 +1108,15 @@
"\n", "\n",
"norm(vec_or_mat)\n", "norm(vec_or_mat)\n",
" Calculate the Frobenius or Euclidean norm of a matrix or vector.\n", " Calculate the Frobenius or Euclidean norm of a matrix or vector.\n",
" \n", "\n",
" Find more infos here: https://en.wikipedia.org/wiki/Matrix_norm#Frobenius_norm\n", " Find more infos here: https://en.wikipedia.org/wiki/Matrix_norm#Frobenius_norm\n",
" \n", "\n",
" Args:\n", " Args:\n",
" vec_or_mat (Vector / Matrix): object whose entries are squared and summed up\n", " vec_or_mat (Vector / Matrix): object whose entries are squared and summed up\n",
" \n", "\n",
" Returns:\n", " Returns:\n",
" norm (float)\n", " norm (float)\n",
" \n", "\n",
" Example Usage:\n", " Example Usage:\n",
" As Vector and Matrix objects are by design non-empty sequences,\n", " As Vector and Matrix objects are by design non-empty sequences,\n",
" norm() may be called, for example, with `[3, 4]` as the argument:\n", " norm() may be called, for example, with `[3, 4]` as the argument:\n",
@ -1453,8 +1459,8 @@
"\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstorage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtyping\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstorage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtyping\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"a vector must have at least one entry\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"a vector must have at least one entry\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFile:\u001b[0m ~/repos/intro-to-python/11_classes/sample_package/vector.py\n", "\u001b[0;31mFile:\u001b[0m ~/Repositories/intro-to-python/11_classes/sample_package/vector.py\n",
"\u001b[0;31mType:\u001b[0m function\n" "\u001b[0;31mType:\u001b[0m function"
] ]
}, },
"metadata": {}, "metadata": {},
@ -1635,8 +1641,8 @@
"\u001b[0;34m Matrix(((1.0, 3.0,), (2.0, 4.0,)))\u001b[0m\n", "\u001b[0;34m Matrix(((1.0, 3.0,), (2.0, 4.0,)))\u001b[0m\n",
"\u001b[0;34m \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFile:\u001b[0m ~/repos/intro-to-python/11_classes/sample_package/matrix.py\n", "\u001b[0;31mFile:\u001b[0m ~/Repositories/intro-to-python/11_classes/sample_package/matrix.py\n",
"\u001b[0;31mType:\u001b[0m function\n" "\u001b[0;31mType:\u001b[0m function"
] ]
}, },
"metadata": {}, "metadata": {},
@ -1748,9 +1754,9 @@
"\u001b[0;34m\u001b[0m \u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\", \"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\", \"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m\"(\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\", \"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrepr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mc\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\",)\"\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mr\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m\"(\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\", \"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrepr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mc\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\",)\"\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mr\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_entries\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34mf\"{name}(({args}))\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34mf\"\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m((\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m))\u001b[0m\u001b[0;34m\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFile:\u001b[0m ~/repos/intro-to-python/11_classes/sample_package/matrix.py\n", "\u001b[0;31mFile:\u001b[0m ~/Repositories/intro-to-python/11_classes/sample_package/matrix.py\n",
"\u001b[0;31mType:\u001b[0m function\n" "\u001b[0;31mType:\u001b[0m function"
] ]
}, },
"metadata": {}, "metadata": {},
@ -1865,8 +1871,8 @@
"\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcolumn\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcolumn\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmatrix_cls\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmatrix_cls\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmatrix_cls\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmatrix_cls\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFile:\u001b[0m ~/repos/intro-to-python/11_classes/sample_package/vector.py\n", "\u001b[0;31mFile:\u001b[0m ~/Repositories/intro-to-python/11_classes/sample_package/vector.py\n",
"\u001b[0;31mType:\u001b[0m function\n" "\u001b[0;31mType:\u001b[0m function"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2122,7 +2128,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Vector(11378937.3105893, ..., 13593029.305789862)[100]\n" "Vector(11378937.310589302, ..., 13593029.305789862)[100]\n"
] ]
} }
], ],
@ -2167,7 +2173,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Matrix((14370711.265265431, ...), ..., (..., 16545418.239505699))[100x100]\n" "Matrix((14370711.26526542, ...), ..., (..., 16545418.239505697))[100x100]\n"
] ]
} }
], ],
@ -2201,7 +2207,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Matrix((32618511.50703142, ...), ..., (..., 32339164.77803234))[50x50]\n" "Matrix((32618511.507031415, ...), ..., (..., 32339164.778032355))[50x50]\n"
] ]
} }
], ],
@ -2265,7 +2271,7 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-55-fd81d962f516>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mA\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[55], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mA\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'tuple'" "\u001b[0;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'tuple'"
] ]
} }
@ -2916,7 +2922,7 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-79-032c970f8cfc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mA_arr\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mA_mat\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "Cell \u001b[0;32mIn[79], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mA_arr\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mA_mat\u001b[49m\n",
"\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (3,3) (9,) " "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (3,3) (9,) "
] ]
} }
@ -2953,7 +2959,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.6" "version": "3.12.2"
}, },
"livereveal": { "livereveal": {
"auto_select": "code", "auto_select": "code",

View file

@ -68,7 +68,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.6" "version": "3.12.2"
}, },
"livereveal": { "livereveal": {
"auto_select": "code", "auto_select": "code",

View file

@ -250,7 +250,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.6" "version": "3.12.2"
}, },
"toc": { "toc": {
"base_numbering": 1, "base_numbering": 1,