insert element in the start of the numpy array
<p>I have array </p>

<pre><code>x=[ 0.30153836  0.30376881  0.29115761  0.29074261  0.28676876 ]
</code></pre>

<p>I want to insert -1 to the start of the array to be like </p>

<pre><code>  x= [-1 0.30153836  0.30376881  0.29115761  0.29074261  0.28676876]
</code></pre>

<p>I tried :</p>

<pre><code>np.insert(x,0,-1,axis=0)
</code></pre>

<p>but it didn't do any change, any idea how to do that ?</p>

<p>I'm not fully familiar with numpy, but it seems that the insert function does not affect the array you pass to it, but rather it returns a new array with the inserted value(s).  You'll have to reassign to x if you really want x to change. </p>

<pre><code>&gt;&gt;&gt; x= [-1, 0.30153836,  0.30376881,  0.29115761,  0.29074261,  0.28676876]
&gt;&gt;&gt; np.insert(x,0,-1,axis=0)
array([-1.        , -1.        ,  0.30153836,  0.30376881,  0.29115761,
        0.29074261,  0.28676876])
&gt;&gt;&gt; x
[-1, 0.30153836, 0.30376881, 0.29115761, 0.29074261, 0.28676876]
&gt;&gt;&gt; x = np.insert(x,0,-1,axis=0)
&gt;&gt;&gt; x
array([-1.        , -1.        ,  0.30153836,  0.30376881,  0.29115761,
        0.29074261,  0.28676876])
</code></pre>

python arrays numpy