![](https://secure.gravatar.com/avatar/d41fa6e1fe29e6c5c5821b5a3f31f190.jpg?s=120&d=mm&r=g)
Hi all, How can I delete a column/row from a matrix. In Matlab:
a=rand(4,4)
a = 0.9501 0.8913 0.8214 0.9218 0.2311 0.7621 0.4447 0.7382 0.6068 0.4565 0.6154 0.1763 0.4860 0.0185 0.7919 0.4057 use
a(:,2)=[]
a = 0.9501 0.8214 0.9218 0.2311 0.4447 0.7382 0.6068 0.6154 0.1763 0.4860 0.7919 0.4057
a(2,:)=[]
a = 0.9501 0.8214 0.9218 0.6068 0.6154 0.1763 0.4860 0.7919 0.4057
Is there something similar in scipy, numpy or numarray ? Any suggestion ? Nils
![](https://secure.gravatar.com/avatar/a53ea657e812241a1162060860f698c4.jpg?s=120&d=mm&r=g)
How can I delete a column/row from a matrix.
As an in-place operation, not at all. To get a copy of an array with some columns/rows removed, use Numeric.take. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@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 -------------------------------------------------------------------------------
![](https://secure.gravatar.com/avatar/c7976f03fcae7e1199d28d1c20e34647.jpg?s=120&d=mm&r=g)
Speaking for numarray, no, not really. But I wonder what is really done for matlab. Either they have a more complex representation of arrays, or all they really are doing is making a new copy of the array and giving you the impression it is being done in place. After all you are changing the size and structure of the array. Perry
![](https://secure.gravatar.com/avatar/a53ea657e812241a1162060860f698c4.jpg?s=120&d=mm&r=g)
On Monday 28 July 2003 16:26, Nils Wagner wrote:
I'd say that the obvious way to implement it is as del a[2:3,:] That can certainly be done, but someone has to do it. Personally, I am not convinced that it is very useful. The consequences of an in-place change can be disastrous when many references point to that array. But then, we have other in-place operations which sometimes are handy, so my usefulness estimation may be wrong. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@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 -------------------------------------------------------------------------------
![](https://secure.gravatar.com/avatar/d41fa6e1fe29e6c5c5821b5a3f31f190.jpg?s=120&d=mm&r=g)
Konrad Hinsen schrieb:
In my opinion, this operation is quite useful. For example a finite element model where we have to impose several homogeneous boundary conditions. This can be done by deleting columns and associated rows. Nils In any case I am interested in a reliable workaround for this feature. A small example would be appreciated. Thanks in advance.
![](https://secure.gravatar.com/avatar/a53ea657e812241a1162060860f698c4.jpg?s=120&d=mm&r=g)
How can I delete a column/row from a matrix.
As an in-place operation, not at all. To get a copy of an array with some columns/rows removed, use Numeric.take. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@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 -------------------------------------------------------------------------------
![](https://secure.gravatar.com/avatar/c7976f03fcae7e1199d28d1c20e34647.jpg?s=120&d=mm&r=g)
Speaking for numarray, no, not really. But I wonder what is really done for matlab. Either they have a more complex representation of arrays, or all they really are doing is making a new copy of the array and giving you the impression it is being done in place. After all you are changing the size and structure of the array. Perry
![](https://secure.gravatar.com/avatar/a53ea657e812241a1162060860f698c4.jpg?s=120&d=mm&r=g)
On Monday 28 July 2003 16:26, Nils Wagner wrote:
I'd say that the obvious way to implement it is as del a[2:3,:] That can certainly be done, but someone has to do it. Personally, I am not convinced that it is very useful. The consequences of an in-place change can be disastrous when many references point to that array. But then, we have other in-place operations which sometimes are handy, so my usefulness estimation may be wrong. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@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 -------------------------------------------------------------------------------
![](https://secure.gravatar.com/avatar/d41fa6e1fe29e6c5c5821b5a3f31f190.jpg?s=120&d=mm&r=g)
Konrad Hinsen schrieb:
In my opinion, this operation is quite useful. For example a finite element model where we have to impose several homogeneous boundary conditions. This can be done by deleting columns and associated rows. Nils In any case I am interested in a reliable workaround for this feature. A small example would be appreciated. Thanks in advance.
participants (4)
-
Konrad Hinsen
-
Nils Wagner
-
Perry Greenfield
-
Ralf Juengling