[Numpy-discussion] split matrix

Nils Wagner nwagner@iam.uni-stuttgart...
Thu Nov 27 14:49:07 CST 2008


On Thu, 27 Nov 2008 17:03:51 +0100
  Uwe Schmitt <uschmitt@mineway.de> wrote:
> Hi,
> 
> is there an effective way to remove a row with a given 
>index from
> a matrix ?
> 

>>> A = rand(10,5)
>>> A
array([[ 0.15976517,  0.29574162,  0.21537014, 
 0.69341324,  0.68713389],
        [ 0.28992634,  0.89714962,  0.90299203, 
 0.22203182,  0.57831945],
        [ 0.23814492,  0.09436163,  0.67062125, 
 0.85923647,  0.64548996],
        [ 0.83215097,  0.85178335,  0.49873409, 
 0.59021905,  0.94631569],
        [ 0.5494401 ,  0.08831399,  0.54776161, 
 0.10043204,  0.88260609],
        [ 0.90951225,  0.40967777,  0.78577964, 
 0.17414472,  0.59568316],
        [ 0.97491997,  0.76869065,  0.88901626, 
 0.69693058,  0.73576195],
        [ 0.25971704,  0.67759869,  0.42972164, 
 0.15069627,  0.13269489],
        [ 0.50012917,  0.5866074 ,  0.32205757,  0.3347558 
,  0.02555147],
        [ 0.66448744,  0.14755343,  0.09963282, 
 0.22277848,  0.35620143]])
>>> ind
array([0, 0, 0, 0, 1, 0, 0, 0, 0, 0])
>>> A = A[ind==0,:][:,:]
>>> A
array([[ 0.15976517,  0.29574162,  0.21537014, 
 0.69341324,  0.68713389],
        [ 0.28992634,  0.89714962,  0.90299203, 
 0.22203182,  0.57831945],
        [ 0.23814492,  0.09436163,  0.67062125, 
 0.85923647,  0.64548996],
        [ 0.83215097,  0.85178335,  0.49873409, 
 0.59021905,  0.94631569],
        [ 0.90951225,  0.40967777,  0.78577964, 
 0.17414472,  0.59568316],
        [ 0.97491997,  0.76869065,  0.88901626, 
 0.69693058,  0.73576195],
        [ 0.25971704,  0.67759869,  0.42972164, 
 0.15069627,  0.13269489],
        [ 0.50012917,  0.5866074 ,  0.32205757,  0.3347558 
,  0.02555147],
        [ 0.66448744,  0.14755343,  0.09963282, 
 0.22277848,  0.35620143]])


Nils

   


More information about the Numpy-discussion mailing list