# [SciPy-user] Numpy for Matlab users

Nils Wagner nwagner at mecha.uni-stuttgart.de
Wed Feb 15 10:45:43 CST 2006

Robert Kern wrote:
>Nils Wagner wrote:
>
>>Robert Kern wrote:
>>
>>
>>>Nils Wagner wrote:
>>>
>>>
>>>>Hi all,
>>>>
>>>>I am converting a Matlab code into  a numpy/scipy  code.
>>>>
>>>>How can I translate
>>>>
>>>>H(k+1,:) = [ ]
>>>>
>>>>into numpy ?
>>>>
>>>Describe what it does in Matlab.
>>>
>>It removes the last row of the matrix.
>>
>>a = rand(4,3)
>>a(4,:) = []
>>Now a  is  a 3 \times 3 matrix
>>
>
>Nothing will change the dimensions like this inplace. Instead, use slices to get
>a new object.
>
>In [1]: a = rand(4,3)
>
>In [2]: a
>Out[2]:
>array([[ 0.09976441,  0.15777107,  0.06565412],
>       [ 0.39381145,  0.66810943,  0.12464937],
>       [ 0.16995962,  0.86150518,  0.67137479],
>       [ 0.13825453,  0.22677347,  0.04551626]])
>
>In [3]: a = a[:3,:]
>
>In [4]: a
>Out[4]:
>array([[ 0.09976441,  0.15777107,  0.06565412],
>       [ 0.39381145,  0.66810943,  0.12464937],
>       [ 0.16995962,  0.86150518,  0.67137479]])
>
>
This might be straightforward if I want to remove the first or last row.

a=a[1:,:]
a=a[:3,:]

but how can I efficiently remove the second or third row w.r.t. to your
example ?

Nils