Browse Source

Console app, NumPy

pull/53/merge
Jure Šorn 2 weeks ago
parent
commit
b85abfe0b2
3 changed files with 16 additions and 20 deletions
  1. 7
      README.md
  2. 18
      index.html
  3. 11
      parse.js

7
README.md

@ -2448,8 +2448,8 @@ def main(screen):
ch = screen.getch()
selected -= (ch == KEY_UP) and (selected > 0)
selected += (ch == KEY_DOWN) and (selected < len(paths)-1)
first = min(first, selected)
first = max(first, selected - (height-1))
first -= (first > selected)
first += (first < selected-(height-1))
if ch in [KEY_LEFT, KEY_RIGHT, KEY_ENTER, ord('\n'), ord('\r')]:
new_dir = '..' if ch == KEY_LEFT else paths[selected]
if os.path.isdir(new_dir):
@ -2703,8 +2703,7 @@ import numpy as np
<1/2d_arr> = <2d>[<2d/1d_bools>] # 1d_bools must have size of a column.
```
* **`':'` returns a slice of all dimension's indices. Omitted dimensions default to `':'`.**
* **Python converts `'obj[i, j]'` to `'obj[(i, j)]'`. This makes `'<2d>[row_i, col_i]'` and `'<2d>[row_indices]'` indistinguishable to NumPy if tuple of indices is passed!**
* **Indexing with a slice and 1d object works the same as when using two slices (lines 4, 6, 7).**
* **Python converts `'obj[i, j]'` to `'obj[(i, j)]'`. This makes `'<2d>[row_i, col_i]'` and `'<2d>[row_indices]'` indistinguishable to NumPy if tuple of two indices is passed!**
* **`'ix_([1, 2], [3, 4])'` returns `'[[1], [2]]'` and `'[[3, 4]]'`. Due to broadcasting rules, this is the same as using `'[[1, 1], [2, 2]]'` and `'[[3, 4], [3, 4]]'`.**
* **Any value that is broadcastable to the indexed shape can be assigned to the selection.**

18
index.html

@ -56,7 +56,7 @@
<body>
<header>
<aside>April 1, 2025</aside>
<aside>April 17, 2025</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -844,11 +844,10 @@ csv.writer(&lt;file&gt;).writerow([&lt;obj&gt;])
<span class="hljs-keyword">raise</span> Exception(&lt;obj&gt;)
</code></pre></div>
<div><h4 id="expressionsthatcallthereprmethod">Expressions that call the repr() method:</h4><pre><code class="python language-python hljs">print/str/repr([&lt;obj&gt;])
print/str/repr({&lt;obj&gt;: &lt;obj&gt;})
<span class="hljs-string">f'<span class="hljs-subst">{&lt;obj&gt;!r}</span>'</span>
<div><h4 id="expressionsthatcallthereprmethod">Expressions that call the repr() method:</h4><pre><code class="python language-python hljs">print/str/repr([&lt;obj&gt;, ...])
print/str/repr({&lt;obj&gt;: &lt;obj&gt;, ...})
Z = make_dataclass(<span class="hljs-string">'Z'</span>, [<span class="hljs-string">'a'</span>]); print/str/repr(Z(&lt;obj&gt;))
<span class="hljs-meta">&gt;&gt;&gt; </span>&lt;obj&gt;
<span class="hljs-string">f'<span class="hljs-subst">{&lt;obj&gt;!r}</span>'</span>
</code></pre></div>
<div><h3 id="inheritance">Inheritance</h3><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>:</span>
@ -2017,8 +2016,8 @@ print(tabulate.tabulate(rows, headers=<span class="hljs-string">'firstrow'</span
ch = screen.getch()
selected -= (ch == KEY_UP) <span class="hljs-keyword">and</span> (selected &gt; <span class="hljs-number">0</span>)
selected += (ch == KEY_DOWN) <span class="hljs-keyword">and</span> (selected &lt; len(paths)-<span class="hljs-number">1</span>)
first = min(first, selected)
first = max(first, selected - (height-<span class="hljs-number">1</span>))
first -= (first &gt; selected)
first += (first &lt; selected-(height-<span class="hljs-number">1</span>))
<span class="hljs-keyword">if</span> ch <span class="hljs-keyword">in</span> [KEY_LEFT, KEY_RIGHT, KEY_ENTER, ord(<span class="hljs-string">'\n'</span>), ord(<span class="hljs-string">'\r'</span>)]:
new_dir = <span class="hljs-string">'..'</span> <span class="hljs-keyword">if</span> ch == KEY_LEFT <span class="hljs-keyword">else</span> paths[selected]
<span class="hljs-keyword">if</span> os.path.isdir(new_dir):
@ -2222,8 +2221,7 @@ $ snakeviz test.prof <span class="hlj
</code></pre>
<ul>
<li><strong><code class="python hljs"><span class="hljs-string">':'</span></code> returns a slice of all dimension's indices. Omitted dimensions default to <code class="python hljs"><span class="hljs-string">':'</span></code>.</strong></li>
<li><strong>Python converts <code class="python hljs"><span class="hljs-string">'obj[i, j]'</span></code> to <code class="python hljs"><span class="hljs-string">'obj[(i, j)]'</span></code>. This makes <code class="python hljs"><span class="hljs-string">'&lt;2d&gt;[row_i, col_i]'</span></code> and <code class="python hljs"><span class="hljs-string">'&lt;2d&gt;[row_indices]'</span></code> indistinguishable to NumPy if tuple of indices is passed!</strong></li>
<li><strong>Indexing with a slice and 1d object works the same as when using two slices (lines 4, 6, 7).</strong></li>
<li><strong>Python converts <code class="python hljs"><span class="hljs-string">'obj[i, j]'</span></code> to <code class="python hljs"><span class="hljs-string">'obj[(i, j)]'</span></code>. This makes <code class="python hljs"><span class="hljs-string">'&lt;2d&gt;[row_i, col_i]'</span></code> and <code class="python hljs"><span class="hljs-string">'&lt;2d&gt;[row_indices]'</span></code> indistinguishable to NumPy if tuple of two indices is passed!</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'ix_([1, 2], [3, 4])'</span></code> returns <code class="python hljs"><span class="hljs-string">'[[1], [2]]'</span></code> and <code class="python hljs"><span class="hljs-string">'[[3, 4]]'</span></code>. Due to broadcasting rules, this is the same as using <code class="python hljs"><span class="hljs-string">'[[1, 1], [2, 2]]'</span></code> and <code class="python hljs"><span class="hljs-string">'[[3, 4], [3, 4]]'</span></code>.</strong></li>
<li><strong>Any value that is broadcastable to the indexed shape can be assigned to the selection.</strong></li>
</ul>
@ -2944,7 +2942,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the active
<footer>
<aside>April 1, 2025</aside>
<aside>April 17, 2025</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

11
parse.js

@ -80,11 +80,10 @@ const PARAMETRIZED_DECORATOR =
' <span class="hljs-keyword">return</span> x + y\n';
const REPR_USE_CASES =
'print/str/repr([&lt;obj&gt;])\n' +
'print/str/repr({&lt;obj&gt;: &lt;obj&gt;})\n' +
'<span class="hljs-string">f\'<span class="hljs-subst">{&lt;obj&gt;!r}</span>\'</span>\n' +
'print/str/repr([&lt;obj&gt;, ...])\n' +
'print/str/repr({&lt;obj&gt;: &lt;obj&gt;, ...})\n' +
'Z = make_dataclass(<span class="hljs-string">\'Z\'</span>, [<span class="hljs-string">\'a\'</span>]); print/str/repr(Z(&lt;obj&gt;))\n' +
'<span class="hljs-meta">&gt;&gt;&gt; </span>&lt;obj&gt;\n';
'<span class="hljs-string">f\'<span class="hljs-subst">{&lt;obj&gt;!r}</span>\'</span>\n';
const CONSTRUCTOR_OVERLOADING =
'<span class="hljs-class"><span class="hljs-keyword">class</span> &lt;<span class="hljs-title">name</span>&gt;:</span>\n' +
@ -188,8 +187,8 @@ const CURSES =
' ch = screen.getch()\n' +
' selected -= (ch == KEY_UP) <span class="hljs-keyword">and</span> (selected &gt; <span class="hljs-number">0</span>)\n' +
' selected += (ch == KEY_DOWN) <span class="hljs-keyword">and</span> (selected &lt; len(paths)-<span class="hljs-number">1</span>)\n' +
' first = min(first, selected)\n' +
' first = max(first, selected - (height-<span class="hljs-number">1</span>))\n' +
' first -= (first &gt; selected)\n' +
' first += (first &lt; selected-(height-<span class="hljs-number">1</span>))\n' +
' <span class="hljs-keyword">if</span> ch <span class="hljs-keyword">in</span> [KEY_LEFT, KEY_RIGHT, KEY_ENTER, ord(<span class="hljs-string">\'\\n\'</span>), ord(<span class="hljs-string">\'\\r\'</span>)]:\n' +
' new_dir = <span class="hljs-string">\'..\'</span> <span class="hljs-keyword">if</span> ch == KEY_LEFT <span class="hljs-keyword">else</span> paths[selected]\n' +
' <span class="hljs-keyword">if</span> os.path.isdir(new_dir):\n' +

|||||||
100:0
Loading…
Cancel
Save