[Numpy-discussion] Row/Column delete

Konrad Hinsen hinsen at cnrs-orleans.fr
Tue Sep 12 07:02:49 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 Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-
Rue Charles Sadron                       | Fax:  +33-
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais

More information about the Numpy-discussion mailing list