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
Copy file name to clipboardExpand all lines: README.md
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2710,7 +2710,7 @@ import numpy as np
2710
2710
<1/2d_arr> = <2d>[<2d/1d_bools>] # 1d_bools must have size of a column.
2711
2711
```
2712
2712
***`':'` returns a slice of all dimension's indices. Omitted dimensions default to `':'`.**
2713
-
***Sixth line fails if tuple is used because Python converts `'obj[i, j]'` to `'obj[(i, j)]'`!**
2713
+
***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!**
2714
2714
***Indexing with a slice and 1d array works the same as when using two slices (lines 4, 6, 7).**
2715
2715
***`'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]]'`.**
2716
2716
***Any value that is broadcastable to the indexed shape can be assigned to the selection.**
<li><strong><codeclass="python hljs"><spanclass="hljs-string">':'</span></code> returns a slice of all dimension's indices. Omitted dimensions default to <codeclass="python hljs"><spanclass="hljs-string">':'</span></code>.</strong></li>
2214
-
<li><strong>Sixth line fails if tuple is used because Python converts <codeclass="python hljs"><spanclass="hljs-string">'obj[i, j]'</span></code> to <codeclass="python hljs"><spanclass="hljs-string">'obj[(i, j)]'</span></code>!</strong></li>
2214
+
<li><strong>Python converts <codeclass="python hljs"><spanclass="hljs-string">'obj[i, j]'</span></code> to <codeclass="python hljs"><spanclass="hljs-string">'obj[(i, j)]'</span></code>. This makes <codeclass="python hljs"><spanclass="hljs-string">'<2d>[row_i, col_i]'</span></code> and <codeclass="python hljs"><spanclass="hljs-string">'<2d>[row_indices]'</span></code> indistinguishable to NumPy if tuple of indices is passed!</strong></li>
2215
2215
<li><strong>Indexing with a slice and 1d array works the same as when using two slices (lines 4, 6, 7).</strong></li>
2216
2216
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'ix_([1, 2], [3, 4])'</span></code> returns <codeclass="python hljs"><spanclass="hljs-string">'[[1], [2]]'</span></code> and <codeclass="python hljs"><spanclass="hljs-string">'[[3, 4]]'</span></code>. Due to broadcasting rules, this is the same as using <codeclass="python hljs"><spanclass="hljs-string">'[[1, 1], [2, 2]]'</span></code> and <codeclass="python hljs"><spanclass="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>
<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.6</span>, <spanclass="hljs-number">0.8</span>], <spanclass="hljs-comment"># Shape: (3, 3) <- !</span>
<div><h3id="example-3">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