|
55 | 55 |
|
56 | 56 | <body> |
57 | 57 | <header> |
58 | | - <aside>December 25, 2024</aside> |
| 58 | + <aside>December 26, 2024</aside> |
59 | 59 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
60 | 60 | </header> |
61 | 61 |
|
|
978 | 978 | <div><h3 id="iterator-1">Iterator</h3><ul> |
979 | 979 | <li><strong>Any object that has methods next() and iter() is an iterator.</strong></li> |
980 | 980 | <li><strong>Next() should return next item or raise StopIteration exception.</strong></li> |
981 | | -<li><strong>Iter() should return 'self'.</strong></li> |
| 981 | +<li><strong>Iter() should return 'self', i.e. unmodified object on which it was called.</strong></li> |
982 | 982 | </ul><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Counter</span>:</span> |
983 | 983 | <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self)</span>:</span> |
984 | 984 | self.i = <span class="hljs-number">0</span> |
@@ -2216,13 +2216,13 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2216 | 2216 | <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> |
2217 | 2217 | <li><strong>Any value that is broadcastable to the indexed shape can be assigned to the selection.</strong></li> |
2218 | 2218 | </ul> |
2219 | | -<div><h3 id="broadcasting">Broadcasting</h3><p><strong>A set of rules by which NumPy functions operate on arrays of different shapes.</strong></p><pre><code class="python language-python hljs">left = np.array([ <span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span> ]) <span class="hljs-comment"># `left.shape == (3,)`</span> |
2220 | | -right = np.array([[<span class="hljs-number">0.1</span>],[<span class="hljs-number">0.6</span>],[<span class="hljs-number">0.8</span>]]) <span class="hljs-comment"># `right.shape == (3, 1)`</span> |
| 2219 | +<div><h3 id="broadcasting">Broadcasting</h3><p><strong>A set of rules by which NumPy functions operate on arrays of different shapes.</strong></p><pre><code class="python language-python hljs">left = np.array([<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>]) <span class="hljs-comment"># `left.shape == (3,)`</span> |
| 2220 | +right = np.array([[<span class="hljs-number">0.1</span>], [<span class="hljs-number">0.6</span>], [<span class="hljs-number">0.8</span>]]) <span class="hljs-comment"># `right.shape == (3, 1)`</span> |
2221 | 2221 | </code></pre></div> |
2222 | 2222 |
|
2223 | 2223 |
|
2224 | 2224 | <div><h4 id="1ifarrayshapesdifferinlengthleftpadtheshortershapewithones">1. If array shapes differ in length, left-pad the shorter shape with ones:</h4><pre><code class="python language-python hljs">left = np.array([[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>]]) <span class="hljs-comment"># `left.shape == (1, 3)`</span> |
2225 | | -right = np.array([[<span class="hljs-number">0.1</span>],[<span class="hljs-number">0.6</span>],[<span class="hljs-number">0.8</span>]]) <span class="hljs-comment"># `right.shape == (3, 1)`</span> |
| 2225 | +right = np.array([[<span class="hljs-number">0.1</span>], [<span class="hljs-number">0.6</span>], [<span class="hljs-number">0.8</span>]]) <span class="hljs-comment"># `right.shape == (3, 1)`</span> |
2226 | 2226 | </code></pre></div> |
2227 | 2227 |
|
2228 | 2228 | <div><h4 id="2ifanydimensionsdifferinsizeexpandtheonesthathavesize1byduplicatingtheirelements">2. If any dimensions differ in size, expand the ones that have size 1 by duplicating their elements:</h4><pre><code class="python language-python hljs">left = np.array([[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>], <span class="hljs-comment"># `left.shape == (3, 3)`</span> |
@@ -2868,7 +2868,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2868 | 2868 |
|
2869 | 2869 | <div><h2 id="appendix"><a href="#appendix" name="appendix">#</a>Appendix</h2><div><h3 id="cython">Cython</h3><p><strong>Library that compiles Python-like code into C.</strong></p><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install cython</span> |
2870 | 2870 | <span class="hljs-keyword">import</span> pyximport; pyximport.install() <span class="hljs-comment"># Module that runs imported Cython scripts.</span> |
2871 | | -<span class="hljs-keyword">import</span> <cython_script> <span class="hljs-comment"># Script's filename needs a '.pyx' extension.</span> |
| 2871 | +<span class="hljs-keyword">import</span> <cython_script> <span class="hljs-comment"># Script must be saved with '.pyx' extension.</span> |
2872 | 2872 | <cython_script>.main() <span class="hljs-comment"># Main() isn't automatically executed.</span> |
2873 | 2873 | </code></pre></div></div> |
2874 | 2874 |
|
@@ -2934,7 +2934,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2934 | 2934 |
|
2935 | 2935 |
|
2936 | 2936 | <footer> |
2937 | | - <aside>December 25, 2024</aside> |
| 2937 | + <aside>December 26, 2024</aside> |
2938 | 2938 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
2939 | 2939 | </footer> |
2940 | 2940 |
|
|
0 commit comments