Python: Why can't I assign new value to an array in this case?
<pre><code>import numpy as np

data = np.array([['Height', 'Weight'],['165', '48'],['168', '50'],['173', '53']])
data[0,0] = data[0,0] + "_1"
</code></pre>

<p><strong>data[0,0]</strong> is <strong>'Height'</strong>, and I want to replace it with <strong>'Height_1'</strong>. But the code above doesn't work. It returned the result as:</p>

<pre><code>data[0,0]
</code></pre>

<blockquote>
  <p>'Height'</p>
</blockquote>

<p>The <strong>data[0,0]</strong> element remained the same. And if I replace it directly without referring to itself, it still doesn't work.</p>

<pre><code>data[0,0] = "Height" + "_1"
</code></pre>

<p>result:</p>

<pre><code>data[0,0]
</code></pre>

<blockquote>
  <p>'Height'</p>
</blockquote>

<p>But if I replace it with some characters other than <strong>"Height"</strong>, it works.</p>

<pre><code>data[0,0] = "str" + "_1"
</code></pre>

<p>Result:</p>

<pre><code>data[0,0]
</code></pre>

<blockquote>
  <p>'str_1'</p>
</blockquote>

<p>I took this case to explain the problem I'm coming across. And in my work I have to refer to the array itself because I need to replace the elements which don't meet some requirements. Anyone have solutions on this? Thank you.</p>

<p>specify an <strong>object</strong> type for your array, such as:</p>

<pre><code>a = np.array([['Height', 'Weight'],['165', '48'],['168', '50'],['173', '53']],dtype=object)
</code></pre>

<p>Then, 
<code>a[0][0]+='_1'</code> will do the trick, you will get:</p>

<pre><code>array([['Height_1', 'Weight'],
       ['165', '48'],
       ['168', '50'],
       ['173', '53']], dtype=object)
</code></pre>

python arrays numpy variable-assignment