Slice numpy array to make it desired shaped
<p>Surprisingly, couldn't find the answer across the internet. I have an n-dimensional numpy array. E.g.: 2-D np array:</p>

<pre><code>array([['34.5500000', '36.9000000', '37.3200000', '37.6700000'],
       ['41.7900000', '44.8000000', '48.2600000', '46.1800000'],
       ['36.1200000', '37.1500000', '39.3100000', '38.1000000'],
       ['82.1000000', '82.0900000', '76.0200000', '77.7000000'],
       ['48.0100000', '51.2500000', '51.1700000', '52.5000000', '55.2500000'],
       ['39.7500000', '39.5000000', '36.8100000', '37.2500000']], dtype=object)
</code></pre>

<p>As you can see, the 5th row consists of 5 elemnts and <strong>i want to make the 5th dissapear</strong>, using something like this:</p>

<pre><code>np.slice(MyArray, [6,4]) 
</code></pre>

<p>[6,4] is a shape. I really DO not want to iterate threw dimensions and cut them. I tried the <code>resize</code> method, but it returns nothing!</p>

<p>This is not a 2d array.  It is a 1d array, whose elements are objects, in this case some 4 element lists and one 5 element one.  And this lists contain strings.</p>

<pre><code>In [577]: np.array([['34.5500000', '36.9000000', '37.3200000', '37.6700000'],
     ...:        ['41.7900000', '44.8000000', '48.2600000', '46.1800000'],
     ...:        ['36.1200000', '37.1500000', '39.3100000', '38.1000000'],
     ...:        ['82.1000000', '82.0900000', '76.0200000', '77.7000000'],
     ...:        ['48.0100000', '51.2500000', '51.1700000', '52.5000000', '55.25
     ...: 00000'],
     ...:        ['39.7500000', '39.5000000', '36.8100000', '37.2500000']], dtyp
     ...: e=object)
Out[577]: 
array([['34.5500000', '36.9000000', '37.3200000', '37.6700000'],
       ['41.7900000', '44.8000000', '48.2600000', '46.1800000'],
       ['36.1200000', '37.1500000', '39.3100000', '38.1000000'],
       ['82.1000000', '82.0900000', '76.0200000', '77.7000000'],
       ['48.0100000', '51.2500000', '51.1700000', '52.5000000', '55.2500000'],
       ['39.7500000', '39.5000000', '36.8100000', '37.2500000']], dtype=object)
In [578]: MyArray=_
In [579]: MyArray.shape
Out[579]: (6,)
In [580]: MyArray[0]
Out[580]: ['34.5500000', '36.9000000', '37.3200000', '37.6700000']
In [581]: MyArray[5]
Out[581]: ['39.7500000', '39.5000000', '36.8100000', '37.2500000']
In [582]: MyArray[4]
Out[582]: ['48.0100000', '51.2500000', '51.1700000', '52.5000000', '55.2500000']
In [583]: 
</code></pre>

<p>To <code>slice</code> this you need to iterate on the elements of the array</p>

<pre><code>In [584]: [d[:4] for d in MyArray]
Out[584]: 
[['34.5500000', '36.9000000', '37.3200000', '37.6700000'],
 ['41.7900000', '44.8000000', '48.2600000', '46.1800000'],
 ['36.1200000', '37.1500000', '39.3100000', '38.1000000'],
 ['82.1000000', '82.0900000', '76.0200000', '77.7000000'],
 ['48.0100000', '51.2500000', '51.1700000', '52.5000000'],
 ['39.7500000', '39.5000000', '36.8100000', '37.2500000']]
</code></pre>

<p>Now with all the sublists the same length, <code>np.array</code> will create a 2d array:</p>

<pre><code>In [585]: np.array(_)
Out[585]: 
array([['34.5500000', '36.9000000', '37.3200000', '37.6700000'],
       ['41.7900000', '44.8000000', '48.2600000', '46.1800000'],
       ['36.1200000', '37.1500000', '39.3100000', '38.1000000'],
       ['82.1000000', '82.0900000', '76.0200000', '77.7000000'],
       ['48.0100000', '51.2500000', '51.1700000', '52.5000000'],
       ['39.7500000', '39.5000000', '36.8100000', '37.2500000']], 
      dtype='&lt;U10')
</code></pre>

<p>Still strings, though</p>

<pre><code>In [586]: np.array(__,dtype=float)
Out[586]: 
array([[ 34.55,  36.9 ,  37.32,  37.67],
       [ 41.79,  44.8 ,  48.26,  46.18],
       [ 36.12,  37.15,  39.31,  38.1 ],
       [ 82.1 ,  82.09,  76.02,  77.7 ],
       [ 48.01,  51.25,  51.17,  52.5 ],
       [ 39.75,  39.5 ,  36.81,  37.25]])
</code></pre>

python arrays numpy