Show only the necessary decimals

This commit is contained in:
Alexander Hess 2020-10-28 16:57:48 +01:00
commit ca9df9e440
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
6 changed files with 152 additions and 150 deletions

View file

@ -1083,13 +1083,13 @@
" # ...\n",
"\n",
" def __repr__(self):\n",
" args = \", \".join(f\"{x:.3f}\" for x in self._entries)\n",
" args = \", \".join(repr(x) for x in self._entries)\n",
" return f\"Vector(({args}))\"\n",
"\n",
" def __str__(self):\n",
" first, last = self._entries[0], self._entries[-1]\n",
" n_entries = len(self._entries)\n",
" return f\"Vector({first:.1f}, ..., {last:.1f})[{n_entries:d}]\""
" return f\"Vector({first!r}, ..., {last!r})[{n_entries:d}]\""
]
},
{
@ -1132,7 +1132,7 @@
{
"data": {
"text/plain": [
"Vector((1.000, 2.000, 3.000))"
"Vector((1.0, 2.0, 3.0))"
]
},
"execution_count": 31,
@ -1167,7 +1167,7 @@
{
"data": {
"text/plain": [
"Vector((1.000, 2.000, 3.000))"
"Vector((1.0, 2.0, 3.0))"
]
},
"execution_count": 32,
@ -1176,7 +1176,7 @@
}
],
"source": [
"Vector((1.000, 2.000, 3.000))"
"Vector((1.0, 2.0, 3.0))"
]
},
{
@ -1202,7 +1202,7 @@
{
"data": {
"text/plain": [
"'Vector((1.000, 2.000, 3.000))'"
"'Vector((1.0, 2.0, 3.0))'"
]
},
"execution_count": 33,
@ -1334,13 +1334,13 @@
" raise ValueError(\"a matrix must have at least one entry\")\n",
"\n",
" def __repr__(self):\n",
" args = \", \".join(\"(\" + \", \".join(f\"{c:.3f}\" for c in r) + \",)\" for r in self._entries)\n",
" args = \", \".join(\"(\" + \", \".join(repr(c) for c in r) + \",)\" for r in self._entries)\n",
" return f\"Matrix(({args}))\"\n",
"\n",
" def __str__(self):\n",
" first, last = self._entries[0][0], self._entries[-1][-1]\n",
" m, n = len(self._entries), len(self._entries[0])\n",
" return f\"Matrix(({first:.1f}, ...), ..., (..., {last:.1f}))[{m:d}x{n:d}]\""
" return f\"Matrix(({first!r}, ...), ..., (..., {last!r}))[{m:d}x{n:d}]\""
]
},
{
@ -1521,7 +1521,7 @@
{
"data": {
"text/plain": [
"Matrix(((1.000, 2.000, 3.000,), (4.000, 5.000, 6.000,), (7.000, 8.000, 9.000,)))"
"Matrix(((1.0, 2.0, 3.0,), (4.0, 5.0, 6.0,), (7.0, 8.0, 9.0,)))"
]
},
"execution_count": 43,
@ -1660,7 +1660,7 @@
" # ...\n",
"\n",
" def __repr__(self):\n",
" args = \", \".join(\"(\" + \", \".join(f\"{c:.3f}\" for c in r) + \",)\" for r in self._entries)\n",
" args = \", \".join(\"(\" + \", \".join(repr(c) for c in r) + \",)\" for r in self._entries)\n",
" return f\"Matrix(({args}))\"\n",
"\n",
" def transpose(self):\n",
@ -1703,7 +1703,7 @@
{
"data": {
"text/plain": [
"Matrix(((1.000, 2.000, 3.000,), (4.000, 5.000, 6.000,), (7.000, 8.000, 9.000,)))"
"Matrix(((1.0, 2.0, 3.0,), (4.0, 5.0, 6.0,), (7.0, 8.0, 9.0,)))"
]
},
"execution_count": 49,
@ -1727,7 +1727,7 @@
{
"data": {
"text/plain": [
"Matrix(((1.000, 4.000, 7.000,), (2.000, 5.000, 8.000,), (3.000, 6.000, 9.000,)))"
"Matrix(((1.0, 4.0, 7.0,), (2.0, 5.0, 8.0,), (3.0, 6.0, 9.0,)))"
]
},
"execution_count": 50,
@ -1775,7 +1775,7 @@
{
"data": {
"text/plain": [
"Matrix(((1.000, 2.000, 3.000,), (4.000, 5.000, 6.000,), (7.000, 8.000, 9.000,)))"
"Matrix(((1.0, 2.0, 3.0,), (4.0, 5.0, 6.0,), (7.0, 8.0, 9.0,)))"
]
},
"execution_count": 52,
@ -1876,7 +1876,7 @@
" # ...\n",
"\n",
" def __repr__(self):\n",
" args = \", \".join(\"(\" + \", \".join(f\"{c:.3f}\" for c in r) + \",)\" for r in self._entries)\n",
" args = \", \".join(\"(\" + \", \".join(repr(c) for c in r) + \",)\" for r in self._entries)\n",
" return f\"Matrix(({args}))\"\n",
"\n",
" def transpose(self):\n",
@ -1923,7 +1923,7 @@
{
"data": {
"text/plain": [
"Matrix(((1.000, 2.000, 3.000,), (4.000, 5.000, 6.000,), (7.000, 8.000, 9.000,)))"
"Matrix(((1.0, 2.0, 3.0,), (4.0, 5.0, 6.0,), (7.0, 8.0, 9.0,)))"
]
},
"execution_count": 57,
@ -1993,7 +1993,7 @@
" raise ValueError(\"a matrix must have at least one entry\")\n",
"\n",
" def __repr__(self):\n",
" args = \", \".join(\"(\" + \", \".join(f\"{c:.3f}\" for c in r) + \",)\" for r in self._entries)\n",
" args = \", \".join(\"(\" + \", \".join(repr(c) for c in r) + \",)\" for r in self._entries)\n",
" return f\"Matrix(({args}))\"\n",
"\n",
" @property\n",