Browse Source

Context manager, Operator, NumPy

pull/187/head
Jure Šorn 7 months ago
parent
commit
e242659d0d
2 changed files with 6 additions and 6 deletions
  1. 6
      README.md
  2. 6
      index.html

6
README.md

@ -1199,7 +1199,7 @@ class Counter:
```
### Context Manager
* **With statements only work with objects that have enter() and exit() special methods.**
* **With statements only work on objects that have enter() and exit() special methods.**
* **Enter() should lock the resources and optionally return an object.**
* **Exit() should release the resources.**
* **Any exception that happens inside the with block is passed to the exit() method.**
@ -2160,7 +2160,7 @@ Operator
```python
import operator as op
<bool> = op.not_(<obj>) # or, and, not (or/and missing)
<bool> = op.eq/ne/lt/le/gt/ge/contains/is_(<obj>, <obj>) # ==, !=, <, <=, >, >=, in, is
<bool> = op.eq/ne/lt/le/gt/ge/is_/contains(<obj>, <obj>) # ==, !=, <, <=, >, >=, is, in
<obj> = op.or_/xor/and_(<int/set>, <int/set>) # |, ^, &
<int> = op.lshift/rshift(<int>, <int>) # <<, >>
<obj> = op.add/sub/mul/truediv/floordiv/mod(<obj>, <obj>) # +, -, *, /, //, %
@ -2666,7 +2666,7 @@ import numpy as np
```python
<array> = np.copy/abs/sqrt/log/int64(<array>) # Returns new array of the same shape.
<array> = <array>.sum/max/mean/argmax/all(axis) # Passed dimension gets aggregated.
<array> = <array>.sum/max/mean/argmax/all(axis) # Aggregates specified dimension.
<array> = np.apply_along_axis(<func>, axis, <array>) # Func can return a scalar or array.
```

6
index.html

@ -1017,7 +1017,7 @@ Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span clas
(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
</code></pre>
<div><h3 id="contextmanager">Context Manager</h3><ul>
<li><strong>With statements only work with objects that have enter() and exit() special methods.</strong></li>
<li><strong>With statements only work on objects that have enter() and exit() special methods.</strong></li>
<li><strong>Enter() should lock the resources and optionally return an object.</strong></li>
<li><strong>Exit() should release the resources.</strong></li>
<li><strong>Any exception that happens inside the with block is passed to the exit() method.</strong></li>
@ -1781,7 +1781,7 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-
</ul>
<div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators. Functions are ordered by operator precedence, starting with least binding.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> operator <span class="hljs-keyword">as</span> op
&lt;bool&gt; = op.not_(&lt;obj&gt;) <span class="hljs-comment"># or, and, not (or/and missing)</span>
&lt;bool&gt; = op.eq/ne/lt/le/gt/ge/contains/is_(&lt;obj&gt;, &lt;obj&gt;) <span class="hljs-comment"># ==, !=, &lt;, &lt;=, &gt;, &gt;=, in, is</span>
&lt;bool&gt; = op.eq/ne/lt/le/gt/ge/is_/contains(&lt;obj&gt;, &lt;obj&gt;) <span class="hljs-comment"># ==, !=, &lt;, &lt;=, &gt;, &gt;=, is, in</span>
&lt;obj&gt; = op.or_/xor/and_(&lt;int/set&gt;, &lt;int/set&gt;) <span class="hljs-comment"># |, ^, &amp;</span>
&lt;int&gt; = op.lshift/rshift(&lt;int&gt;, &lt;int&gt;) <span class="hljs-comment"># &lt;&lt;, &gt;&gt;</span>
&lt;obj&gt; = op.add/sub/mul/truediv/floordiv/mod(&lt;obj&gt;, &lt;obj&gt;) <span class="hljs-comment"># +, -, *, /, //, %</span>
@ -2190,7 +2190,7 @@ $ snakeviz test.prof <span class="hlj
&lt;view&gt; = &lt;array&gt;.transpose() <span class="hljs-comment"># Or: &lt;array&gt;.T</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;array&gt; = np.copy/abs/sqrt/log/int64(&lt;array&gt;) <span class="hljs-comment"># Returns new array of the same shape.</span>
&lt;array&gt; = &lt;array&gt;.sum/max/mean/argmax/all(axis) <span class="hljs-comment"># Passed dimension gets aggregated.</span>
&lt;array&gt; = &lt;array&gt;.sum/max/mean/argmax/all(axis) <span class="hljs-comment"># Aggregates specified dimension.</span>
&lt;array&gt; = np.apply_along_axis(&lt;func&gt;, axis, &lt;array&gt;) <span class="hljs-comment"># Func can return a scalar or array.</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;array&gt; = np.concatenate(&lt;list_of_arrays&gt;, axis=<span class="hljs-number">0</span>) <span class="hljs-comment"># Links arrays along first axis (rows).</span>

Loading…
Cancel
Save