MCPcopy Create free account
hub / github.com/numpy/numpy / bmat

Function bmat

numpy/matrixlib/defmatrix.py:1037–1112  ·  view source on GitHub ↗

Build a matrix object from a string, nested sequence, or array. Parameters ---------- obj : str or array_like Input data. If a string, variables in the current scope may be referenced by name. ldict : dict, optional A dictionary that replaces local opera

(obj, ldict=None, gdict=None)

Source from the content-addressed store, hash-verified

1035
1036@set_module('numpy')
1037def bmat(obj, ldict=None, gdict=None):
1038 """
1039 Build a matrix object from a string, nested sequence, or array.
1040
1041 Parameters
1042 ----------
1043 obj : str or array_like
1044 Input data. If a string, variables in the current scope may be
1045 referenced by name.
1046 ldict : dict, optional
1047 A dictionary that replaces local operands in current frame.
1048 Ignored if `obj` is not a string or `gdict` is None.
1049 gdict : dict, optional
1050 A dictionary that replaces global operands in current frame.
1051 Ignored if `obj` is not a string.
1052
1053 Returns
1054 -------
1055 out : matrix
1056 Returns a matrix object, which is a specialized 2-D array.
1057
1058 See Also
1059 --------
1060 block :
1061 A generalization of this function for N-d arrays, that returns normal
1062 ndarrays.
1063
1064 Examples
1065 --------
1066 >>> A = np.mat('1 1; 1 1')
1067 >>> B = np.mat('2 2; 2 2')
1068 >>> C = np.mat('3 4; 5 6')
1069 >>> D = np.mat('7 8; 9 0')
1070
1071 All the following expressions construct the same block matrix:
1072
1073 >>> np.bmat([[A, B], [C, D]])
1074 matrix([[1, 1, 2, 2],
1075 [1, 1, 2, 2],
1076 [3, 4, 7, 8],
1077 [5, 6, 9, 0]])
1078 >>> np.bmat(np.r_[np.c_[A, B], np.c_[C, D]])
1079 matrix([[1, 1, 2, 2],
1080 [1, 1, 2, 2],
1081 [3, 4, 7, 8],
1082 [5, 6, 9, 0]])
1083 >>> np.bmat('A,B; C,D')
1084 matrix([[1, 1, 2, 2],
1085 [1, 1, 2, 2],
1086 [3, 4, 7, 8],
1087 [5, 6, 9, 0]])
1088
1089 """
1090 if isinstance(obj, str):
1091 if gdict is None:
1092 # get previous frame
1093 frame = sys._getframe().f_back
1094 glob_dict = frame.f_globals

Callers 2

test_basicMethod · 0.90

Calls 3

matrixClass · 0.85
_from_stringFunction · 0.85
concatenateFunction · 0.50

Tested by 2

test_basicMethod · 0.72