# [SciPy-user] Numpy for Matlab users

Robert Kern robert.kern at gmail.com
Wed Feb 15 10:40:57 CST 2006

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]])

--
Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter