MCPcopy Index your code
hub / github.com/numpy/numpy / bmat

Function bmat

numpy/matrixlib/defmatrix.py:1041–1117  ·  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

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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…