[SciPy-user] New bmat constructor in SciPy
Nils Wagner
wagner.nils at vdi.de
Tue Sep 23 14:50:18 EDT 2003
-------------------
One of SciPy's goals is to ease transition to Python for Matlab users.
In this context it would be nice to have a tool to remove
rows and columns of 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
Nils
In that light r_[] and c_[] were added some time ago (but perhaps not
well documented)
As I mentioned before
F = r_[c_[A,B],c_[C,D]] would construct F = [A B]
[C D]
now, a new function has been added that does the same thing, but also
creates a matrix object.
bmat (short for build matrix)
bmat([[A,B],[C,D]]) = bmat('A,B; C,D') = bmat(r_[c_[A,B],c_[C,D]])
This returns a Matrix object (* is matrix multiplication for this guy)
constructed from the blocks A, B, C and D.
Of course these blocks must have the right shapes or an error will be
generated.
Incidentally,
r_['A,B;C,D'] does the same thing.
I hope this helps.
-Travis O.
_______________________________________________
SciPy-user mailing list
SciPy-user at scipy.net
http://www.scipy.net/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list