When does advanced indexing on structured masked arrays *really* return a copy?
<p>When I have a structured masked array with boolean indexing, under what conditions do I get a view and when do I get a copy?  The <a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing" rel="nofollow">documentation</a> says that advanced indexing always returns a copy, but this is not true, since something like <code>X[X&gt;0]=42</code> is technically advanced indexing, but the assignment works.  My situation is more complex:</p>

<p>I want to set the mask of a particular field based on a criterion from another field, so I need to get the field, apply the boolean indexing, and get the mask.  There are 3! = 6 orders of doing so.</p>

<p>Preparation:</p>

<pre><code>In [83]: M = ma.MaskedArray(random.random(400).view("f8,f8,f8,f8")).reshape(10, 10)

In [84]: crit = M[:, 4]["f2"] &gt; 0.5
</code></pre>

<ol>
<li><p>Field - index - mask (fails):</p>

<pre><code>In [85]: M["f3"][crit, 3].mask = True

In [86]: print(M["f3"][crit, 3].mask)
[False False False False False]
</code></pre></li>
<li><p>Index - field - mask (fails):</p>

<pre><code>In [87]: M[crit, 3]["f3"].mask = True

In [88]: print(M[crit, 3]["f3"].mask)
[False False False False False]
</code></pre></li>
<li><p>Index - mask - field (fails):</p>

<pre><code>In [94]: M[crit, 3].mask["f3"] = True

In [95]: print(M[crit, 3].mask["f3"])
[False False False False False]
</code></pre></li>
<li><p>Mask - index - field (fails):</p>

<pre><code>In [101]: M.mask[crit, 3]["f3"] = True

In [102]: print(M.mask[crit, 3]["f3"])
[False False False False False]
</code></pre></li>
<li><p>Field - mask - index (succeeds):</p>

<pre><code>In [103]: M["f3"].mask[crit, 3] = True

In [104]: print(M["f3"].mask[crit, 3])
[ True  True  True  True  True]

# set back to False so I can try method #6

In [105]: M["f3"].mask[crit, 3] = False

In [106]: print(M["f3"].mask[crit, 3])
[False False False False False]
</code></pre></li>
<li><p>Mask - field - index (succeeds):</p>

<pre><code>In [107]: M.mask["f3"][crit, 3] = True

In [108]: print(M.mask["f3"][crit, 3])
[ True  True  True  True  True]
</code></pre></li>
</ol>

<p>So, it looks like indexing must come <em>last</em>.</p>