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

Class matrix

numpy/matrixlib/defmatrix.py:74–1009  ·  view source on GitHub ↗

matrix(data, dtype=None, copy=True) .. note:: It is no longer recommended to use this class, even for linear algebra. Instead use regular arrays. The class may be removed in the future. Returns a matrix from an array-like object, or from a string of data.

Source from the content-addressed store, hash-verified

72
73@set_module('numpy')
74class matrix(N.ndarray):
75 """
76 matrix(data, dtype=None, copy=True)
77
78 .. note:: It is no longer recommended to use this class, even for linear
79 algebra. Instead use regular arrays. The class may be removed
80 in the future.
81
82 Returns a matrix from an array-like object, or from a string of data.
83 A matrix is a specialized 2-D array that retains its 2-D nature
84 through operations. It has certain special operators, such as ``*``
85 (matrix multiplication) and ``**`` (matrix power).
86
87 Parameters
88 ----------
89 data : array_like or string
90 If `data` is a string, it is interpreted as a matrix with commas
91 or spaces separating columns, and semicolons separating rows.
92 dtype : data-type
93 Data-type of the output matrix.
94 copy : bool
95 If `data` is already an `ndarray`, then this flag determines
96 whether the data is copied (the default), or whether a view is
97 constructed.
98
99 See Also
100 --------
101 array
102
103 Examples
104 --------
105 >>> a = np.matrix('1 2; 3 4')
106 >>> a
107 matrix([[1, 2],
108 [3, 4]])
109
110 >>> np.matrix([[1, 2], [3, 4]])
111 matrix([[1, 2],
112 [3, 4]])
113
114 """
115 __array_priority__ = 10.0
116 def __new__(subtype, data, dtype=None, copy=True):
117 warnings.warn('the matrix subclass is not the recommended way to '
118 'represent matrices or deal with linear algebra (see '
119 'https://docs.scipy.org/doc/numpy/user/'
120 'numpy-for-matlab-users.html). '
121 'Please adjust your code to use regular ndarray.',
122 PendingDeprecationWarning, stacklevel=2)
123 if isinstance(data, matrix):
124 dtype2 = data.dtype
125 if (dtype is None):
126 dtype = dtype2
127 if (dtype2 == dtype) and (not copy):
128 return data
129 return data.astype(dtype)
130
131 if isinstance(data, N.ndarray):

Callers 15

test_basicMethod · 0.90
test_sumMethod · 0.90
test_prodMethod · 0.90
test_maxMethod · 0.90
test_minMethod · 0.90
test_basicMethod · 0.90
test_pinvMethod · 0.90
test_comparisonsMethod · 0.90
test_noaxisMethod · 0.90
test_reprMethod · 0.90
test_basicMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_basicMethod · 0.72
test_sumMethod · 0.72
test_prodMethod · 0.72
test_maxMethod · 0.72
test_minMethod · 0.72
test_basicMethod · 0.72
test_pinvMethod · 0.72
test_comparisonsMethod · 0.72
test_noaxisMethod · 0.72
test_reprMethod · 0.72
test_basicMethod · 0.72