<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>
<li><strong>Any value that is broadcastable to the indexed shape can be assigned to the selection.</strong></li>
</ul>
<div><h3id="broadcasting">Broadcasting</h3><p><strong>A set of rules by which NumPy functions operate on arrays of different shapes.</strong></p><pre><codeclass="python language-python hljs">left = np.array([<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>]) <spanclass="hljs-comment"># `left.shape == (3,)`</span>
right = np.array([[<spanclass="hljs-number">0.1</span>],[<spanclass="hljs-number">0.6</span>],[<spanclass="hljs-number">0.8</span>]])<spanclass="hljs-comment"># `right.shape == (3, 1)`</span>
<div><h3id="broadcasting">Broadcasting</h3><p><strong>A set of rules by which NumPy functions operate on arrays of different shapes.</strong></p><pre><codeclass="python language-python hljs">left = np.array([<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>])<spanclass="hljs-comment"># `left.shape == (3,)`</span>
right = np.array([[<spanclass="hljs-number">0.1</span>],[<spanclass="hljs-number">0.6</span>],[<spanclass="hljs-number">0.8</span>]]) <spanclass="hljs-comment"># `right.shape == (3, 1)`</span>
</code></pre></div>
<div><h4id="1ifarrayshapesdifferinlengthleftpadtheshortershapewithones">1. If array shapes differ in length, left-pad the shorter shape with ones:</h4><pre><codeclass="python language-python hljs">left = np.array([[<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>]]) <spanclass="hljs-comment"># `left.shape == (1, 3)`</span>
right = np.array([[<spanclass="hljs-number">0.1</span>],[<spanclass="hljs-number">0.6</span>],[<spanclass="hljs-number">0.8</span>]])<spanclass="hljs-comment"># `right.shape == (3, 1)`</span>
right = np.array([[<spanclass="hljs-number">0.1</span>],[<spanclass="hljs-number">0.6</span>],[<spanclass="hljs-number">0.8</span>]]) <spanclass="hljs-comment"># `right.shape == (3, 1)`</span>
</code></pre></div>
<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 = np.array([[<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>], <spanclass="hljs-comment"># `left.shape == (3, 3)`</span>