You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<array>=<array>.argmin(axis) # Returns indexes of smallest elements.
2644
+
<array>= np.apply_along_axis(<func>, axis, <array>) # Func can return a scalar or array.
2651
2645
```
2652
2646
2653
-
***Shape is a tuple of dimension sizes.**
2654
-
***Axis is an index of the dimension that gets aggregated. Leftmost dimension has index 0.**
2647
+
***Shape is a tuple of dimension sizes. A 100x50 RGB image has shape (50, 100, 3).**
2648
+
***Axis is an index of the dimension that gets aggregated. Leftmost/outermost dimension has index 0. Summing a 100x50 RGB image along the axis 2 will return a greyscale image with shape (50, 100).**
2649
+
***Passing a tuple of axes will chain the operations like this: `'<array>.<method>(axis_1, keepdims=True).<method>(axis_2).squeeze()'`.**
<array> = <array>.argmin(axis) <spanclass="hljs-comment"># Returns indexes of smallest elements.</span>
2162
+
<array> = np.apply_along_axis(<func>, axis, <array>) <spanclass="hljs-comment"># Func can return a scalar or array.</span>
2167
2163
</code></pre>
2168
2164
<ul>
2169
-
<li><strong>Shape is a tuple of dimension sizes.</strong></li>
2170
-
<li><strong>Axis is an index of the dimension that gets aggregated. Leftmost dimension has index 0.</strong></li>
2165
+
<li><strong>Shape is a tuple of dimension sizes. A 100x50 RGB image has shape (50, 100, 3).</strong></li>
2166
+
<li><strong>Axis is an index of the dimension that gets aggregated. Leftmost/outermost dimension has index 0. Summing a 100x50 RGB image along the axis 2 will return a greyscale image with shape (50, 100).</strong></li>
2167
+
<li><strong>Passing a tuple of axes will chain the operations like this: <codeclass="python hljs"><spanclass="hljs-string">'<array>.<method>(axis_1, keepdims=True).<method>(axis_2).squeeze()'</span></code>.</strong></li>
<div><h3id="broadcasting">Broadcasting</h3><p><strong>Broadcasting is a set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.</strong></p><pre><codeclass="python language-python hljs">left = [[<spanclass="hljs-number">0.1</span>], [<spanclass="hljs-number">0.6</span>], [<spanclass="hljs-number">0.8</span>]] <spanclass="hljs-comment"># Shape: (3, 1)</span>
<li><strong>All examples also allow assignments.</strong></li>
2183
+
</ul>
2184
+
<div><h3id="broadcasting">Broadcasting</h3><p><strong>Broadcasting is a set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.</strong></p><pre><codeclass="python language-python hljs">left = [[<spanclass="hljs-number">0.1</span>], [<spanclass="hljs-number">0.6</span>], [<spanclass="hljs-number">0.8</span>]] <spanclass="hljs-comment"># Shape: (3, 1)</span>
<div><h4id="2ifanydimensionsdifferinsizeexpandtheonesthathavesize1byduplicatingtheirelements">2. If any dimensions differ in size, expand the ones that have size 1 by duplicating their elements:</h4><pre><codeclass="python language-python hljs">left = [[<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.1</span>], [<spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.6</span>], [<spanclass="hljs-number">0.8</span>, <spanclass="hljs-number">0.8</span>, <spanclass="hljs-number">0.8</span>]] <spanclass="hljs-comment"># Shape: (3, 3) <- !</span>
<div><h4id="2ifanydimensionsdifferinsizeexpandtheonesthathavesize1byduplicatingtheirelements">2. If any dimensions differ in size, expand the ones that have size 1 by duplicating their elements:</h4><pre><codeclass="python language-python hljs">left = [[<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.1</span>], <spanclass="hljs-comment"># Shape: (3, 3) <- !</span>
<div><h4id="3ifneithernonmatchingdimensionhassize1raiseanerror">3. If neither non-matching dimension has size 1, raise an error.</h4><div><h3id="example-1">Example</h3><div><h4id="foreachpointreturnsindexofitsnearestpoint010608121">For each point returns index of its nearest point (<codeclass="python hljs">[<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>] => [<spanclass="hljs-number">1</span>, <spanclass="hljs-number">2</span>, <spanclass="hljs-number">1</span>]</code>):</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>> </span>points = np.array([<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>])
0 commit comments