|
1761 | 1761 |
|
1762 | 1762 | <div><h2 id="deque"><a href="#deque" name="deque">#</a>Deque</h2><p><strong>A thread-safe list with efficient appends and pops from either side. Pronounced "deck".</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> deque
|
1763 | 1763 | <deque> = deque(<collection>, maxlen=<span class="hljs-keyword">None</span>)
|
1764 |
| -<deque>.appendleft(<el>) <span class="hljs-comment"># Opposite element is dropped if full.</span> |
1765 |
| -<el> = <deque>.popleft() <span class="hljs-comment"># Raises IndexError if empty.</span> |
1766 |
| -<deque>.extendleft(<collection>) <span class="hljs-comment"># Collection gets reversed.</span> |
1767 |
| -<deque>.rotate(n=<span class="hljs-number">1</span>) <span class="hljs-comment"># Rotates elements to the right.</span> |
1768 | 1764 | </code></pre></div>
|
1769 | 1765 |
|
1770 | 1766 |
|
| 1767 | +<pre><code class="python language-python hljs"><deque>.appendleft(<el>) <span class="hljs-comment"># Opposite element is dropped if full.</span> |
| 1768 | +<el> = <deque>.popleft() <span class="hljs-comment"># Raises IndexError if empty.</span> |
| 1769 | +<deque>.extendleft(<collection>) <span class="hljs-comment"># Collection gets reversed.</span> |
| 1770 | +<deque>.rotate(n=<span class="hljs-number">1</span>) <span class="hljs-comment"># Rotates elements to the right.</span> |
| 1771 | +</code></pre> |
1771 | 1772 | <div><h2 id="threading"><a href="#threading" name="threading">#</a>Threading</h2><ul>
|
1772 | 1773 | <li><strong>CPython interpreter can only run a single thread at a time.</strong></li>
|
1773 | 1774 | <li><strong>That is why using multiple threads won't result in a faster execution, unless there is an I/O operation in the thread.</strong></li>
|
|
2259 | 2260 | <Image>.putdata(<list/ImagingCore>) <span class="hljs-comment"># Writes a sequence of pixels.</span>
|
2260 | 2261 | <Image>.paste(<Image>, (x, y)) <span class="hljs-comment"># Writes an image to image.</span>
|
2261 | 2262 | </code></pre>
|
2262 |
| -<pre><code class="bash language-bash hljs"><2d_array> = np.array(<Image>) <span class="hljs-comment"># Generates NumPy array from greyscale image.</span> |
2263 |
| -<3d_array> = np.array(<Image>) <span class="hljs-comment"># Generates NumPy array from color image.</span> |
2264 |
| -<Image> = Image.fromarray(<array>) <span class="hljs-comment"># Generates image from NumPy array.</span> |
| 2263 | +<pre><code class="bash language-bash hljs"><2d_array> = np.array(<Image>) <span class="hljs-comment"># Converts greyscale image to NumPy array.</span> |
| 2264 | +<3d_array> = np.array(<Image>) <span class="hljs-comment"># Converts color image to NumPy array.</span> |
| 2265 | +<Image> = Image.fromarray(<array>) <span class="hljs-comment"># Converts NumPy array to Image.</span> |
2265 | 2266 | </code></pre>
|
2266 | 2267 | <div><h3 id="modes-1">Modes</h3><ul>
|
2267 | 2268 | <li><strong><code class="python hljs"><span class="hljs-string">'1'</span></code> - 1-bit pixels, black and white, stored with one pixel per byte.</strong></li>
|
|
0 commit comments