def bmat(obj, ldict=None, gdict=None):
if isinstance(obj, str):<EOL><INDENT>if gdict is None:<EOL><INDENT>frame = sys._getframe().f_back<EOL>glob_dict = frame.f_globals<EOL>loc_dict = frame.f_locals<EOL><DEDENT>else:<EOL><INDENT>glob_dict = gdict<EOL>loc_dict = ldict<EOL><DEDENT>return matrix(_from_string(obj, glob_dict, loc_dict))<EOL><DEDENT>if isinstance(obj, (tuple, list)):<EOL><INDENT>arr_rows = []<EOL>for row in obj:<EOL><INDENT>if isinstance(row, N.ndarray):  <EOL><INDENT>return matrix(concatenate(obj, axis=-<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>arr_rows.append(concatenate(row, axis=-<NUM_LIT:1>))<EOL><DEDENT><DEDENT>return matrix(concatenate(arr_rows, axis=<NUM_LIT:0>))<EOL><DEDENT>if isinstance(obj, N.ndarray):<EOL><INDENT>return matrix(obj)<EOL><DEDENT>
Build a matrix object from a string, nested sequence, or array.

Parameters
----------
obj : str or array_like
    Input data.  Names of variables in the current scope may be
    referenced, even if `obj` is a string.

Returns
-------
out : matrix
    Returns a matrix object, which is a specialized 2-D array.

See Also
--------
matrix

Examples
--------
>>> A = np.mat('1 1; 1 1')
>>> B = np.mat('2 2; 2 2')
>>> C = np.mat('3 4; 5 6')
>>> D = np.mat('7 8; 9 0')

All the following expressions construct the same block matrix:

>>> np.bmat([[A, B], [C, D]])
matrix([[1, 1, 2, 2],
        [1, 1, 2, 2],
        [3, 4, 7, 8],
        [5, 6, 9, 0]])
>>> np.bmat(np.r_[np.c_[A, B], np.c_[C, D]])
matrix([[1, 1, 2, 2],
        [1, 1, 2, 2],
        [3, 4, 7, 8],
        [5, 6, 9, 0]])
>>> np.bmat('A,B; C,D')
matrix([[1, 1, 2, 2],
        [1, 1, 2, 2],
        [3, 4, 7, 8],
        [5, 6, 9, 0]])