[SciPy-user] Numpy for Matlab users

Robert Kern robert.kern at gmail.com
Wed Feb 15 11:06:47 CST 2006


Nils Wagner wrote:
> Robert Kern wrote:
> 
>>Nils Wagner wrote:
>>
>>>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 ?
>>>   
>>
>>Robert Cimrman gave you the answer.
>>
>>>>a=rand(4,3)
>>>>a
> 
> array([[ 0.91343331,  0.78947381,  0.39115252],
>        [ 0.17682632,  0.75310694,  0.0081875 ],
>        [ 0.82873565,  0.08136179,  0.46704486],
>        [ 0.38479685,  0.54347342,  0.21294132]])
> 
>>>>a=a[(0,2,3),:]
>>>>a
> 
> array([[ 0.91343331,  0.78947381,  0.39115252],
>        [ 0.82873565,  0.08136179,  0.46704486],
>        [ 0.38479685,  0.54347342,  0.21294132]])
> 
> But it might be easier to say what I would like to remove instead of
> what I want to keep ...
>  
> Do you agree ?

Sure. Think about lists and the .remove() method. Then you can wrap it into a
function to make it convenient.

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



More information about the SciPy-user mailing list