<p dir="auto">Assigning to field of recarray is not working correctly. Example script is below.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np

rec = np.recarray(1, dtype=[('x', float, 5)])

# Bug behaviour
rec[0].x = 1
print rec[0] # should print: (array([ 1.,  1.,  1.,  1.,  1.]),)
             # but prints uninitialized float values

# Correct behaviour
rec.x = 2
print rec[0] # prints: (array([ 2.,  2.,  2.,  2.,  2.]),)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">rec</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">recarray</span>(<span class="pl-c1">1</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span>[(<span class="pl-s">'x'</span>, <span class="pl-s1">float</span>, <span class="pl-c1">5</span>)])

<span class="pl-c"># Bug behaviour</span>
<span class="pl-s1">rec</span>[<span class="pl-c1">0</span>].<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
<span class="pl-k">print</span> <span class="pl-s1">rec</span>[<span class="pl-c1">0</span>] <span class="pl-c"># should print: (array([ 1.,  1.,  1.,  1.,  1.]),)</span>
             <span class="pl-c"># but prints uninitialized float values</span>

<span class="pl-c"># Correct behaviour</span>
<span class="pl-s1">rec</span>.<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span>
<span class="pl-k">print</span> <span class="pl-s1">rec</span>[<span class="pl-c1">0</span>] <span class="pl-c"># prints: (array([ 2.,  2.,  2.,  2.,  2.]),)</span></pre></div>
<p dir="auto">When assigning arrays inside structured arrays without a left sided <code class="notranslate">[:]</code>, only the first element gets actually assigned. This is shown in the following code snippet, where a structured array is initialized with zeros, and then filled by assignment of an array, and the assignment of a structured array. The assignment of the array only assigns the first value, where the assignment of the structured array assigns all values:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [2]: np.__version__
Out[2]: '1.7.0'
In [3]: struct_dt = np.dtype([
   ...:     ('elem', 'i4', 5),
   ...: ])
In [4]: dt = np.dtype([
   ...:     ('field', 'i4', 10),
   ...:     ('struct', struct_dt)
   ...: ])
In [5]: x = np.zeros(1, dt)
In [6]: x[0]['field']  = np.ones(10, dtype='i4')
In [7]: x[0]['struct'] = np.ones(1, dtype=struct_dt)
In [8]: x
Out[8]: 
array([([1, 0, 0, 0, 0, 0, 0, 0, 0, 0], ([1, 1, 1, 1, 1],))], 
      dtype=[('field', '&lt;i4', (10,)), ('struct', [('elem', '&lt;i4', (5,))])])"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">np</span>.<span class="pl-s1">__version__</span>
<span class="pl-v">Out</span>[<span class="pl-c1">2</span>]: <span class="pl-s">'1.7.0'</span>
<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">struct_dt</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">dtype</span>([
   ...:     (<span class="pl-s">'elem'</span>, <span class="pl-s">'i4'</span>, <span class="pl-c1">5</span>),
   ...: ])
<span class="pl-v">In</span> [<span class="pl-c1">4</span>]: <span class="pl-s1">dt</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">dtype</span>([
   ...:     (<span class="pl-s">'field'</span>, <span class="pl-s">'i4'</span>, <span class="pl-c1">10</span>),
   ...:     (<span class="pl-s">'struct'</span>, <span class="pl-s1">struct_dt</span>)
   ...: ])
<span class="pl-v">In</span> [<span class="pl-c1">5</span>]: <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros</span>(<span class="pl-c1">1</span>, <span class="pl-s1">dt</span>)
<span class="pl-v">In</span> [<span class="pl-c1">6</span>]: <span class="pl-s1">x</span>[<span class="pl-c1">0</span>][<span class="pl-s">'field'</span>]  <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ones</span>(<span class="pl-c1">10</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'i4'</span>)
<span class="pl-v">In</span> [<span class="pl-c1">7</span>]: <span class="pl-s1">x</span>[<span class="pl-c1">0</span>][<span class="pl-s">'struct'</span>] <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ones</span>(<span class="pl-c1">1</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">struct_dt</span>)
<span class="pl-v">In</span> [<span class="pl-c1">8</span>]: <span class="pl-s1">x</span>
<span class="pl-v">Out</span>[<span class="pl-c1">8</span>]: 
<span class="pl-en">array</span>([([<span class="pl-c1">1</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>], ([<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>],))], 
      <span class="pl-s1">dtype</span><span class="pl-c1">=</span>[(<span class="pl-s">'field'</span>, <span class="pl-s">'&lt;i4'</span>, (<span class="pl-c1">10</span>,)), (<span class="pl-s">'struct'</span>, [(<span class="pl-s">'elem'</span>, <span class="pl-s">'&lt;i4'</span>, (<span class="pl-c1">5</span>,))])])</pre></div>
<p dir="auto">The expected result is that all elements of <code class="notranslate">x[0]['field']</code> are 1.</p>
<p dir="auto">However, <code class="notranslate">x[0]['field']</code> "recognizes" some part of the assigned array, as it will complain about broadcasting problems for wrong sizes:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [9]: x[0]['field'] = np.ones(9, dtype='i4')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-9-80d7cbce6711&gt; in &lt;module&gt;()
----&gt; 1 x[0]['field'] = np.ones(9, dtype='i4')

ValueError: could not broadcast input array from shape (9) into shape (9,10)"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">9</span>]: <span class="pl-s1">x</span>[<span class="pl-c1">0</span>][<span class="pl-s">'field'</span>] <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ones</span>(<span class="pl-c1">9</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'i4'</span>)
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">ValueError</span>                                <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">&lt;</span><span class="pl-s1">ipython</span><span class="pl-c1">-</span><span class="pl-s1">input</span><span class="pl-c1">-</span><span class="pl-c1">9</span><span class="pl-c1">-</span><span class="pl-c1">80</span><span class="pl-s1">d7cbce6711</span><span class="pl-c1">&gt;</span> <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">x</span>[<span class="pl-c1">0</span>][<span class="pl-s">'field'</span>] <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ones</span>(<span class="pl-c1">9</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'i4'</span>)

<span class="pl-v">ValueError</span>: <span class="pl-s1">could</span> <span class="pl-c1">not</span> <span class="pl-s1">broadcast</span> <span class="pl-s1">input</span> <span class="pl-s1">array</span> <span class="pl-k">from</span> <span class="pl-en">shape</span> (<span class="pl-c1">9</span>) <span class="pl-s1">into</span> <span class="pl-en">shape</span> (<span class="pl-c1">9</span>,<span class="pl-c1">10</span>)</pre></div>
<p dir="auto">As mentioned in the beginning, adding <code class="notranslate">[:]</code> on the left side (In [6]) will correctly set all elements to 1. If the shown assignment is not allowed, I would have expected that an exception gets raised?</p>