[Numpy-discussion] Row/Column delete

hinsen at dirac.cnrs-orleans.fr hinsen at dirac.cnrs-orleans.fr
Tue Sep 12 07:03:11 CDT 2000


> What I am doing right now is: Set up a new matrix with one less row
> or column (zeros()), then copy all the rows/columns but the one I'd
> like to delete to the new matrix.

I haven't done any comparisons, but I suspect that Numeric.take() is
faster for large arrays. Try this:

def delete_row(matrix, row):
   return Numeric.take(matrix, range(row) + range(row+1, matrix.shape[0]))

def delete_column(matrix, column):
   return Numeric.take(matrix,
                       range(column) + range(column+1, matrix.shape[1]),
                       axis = 1)

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------



More information about the Numpy-discussion mailing list