# [SciPy-user] New bmat constructor in SciPy

Nils Wagner scipy-user@scipy.net
Tue Sep 23 19:50:18 CDT 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@scipy.net
http://www.scipy.net/mailman/listinfo/scipy-user

```