MCPcopy
hub / github.com/numpy/numpy / matrix

Class matrix

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

matrix(data, dtype=None, copy=True) Returns a matrix from an array-like object, or from a string of data. A matrix is a specialized 2-D array that retains its 2-D nature through operations. It has certain special operators, such as ``*`` (matrix multiplication) and ``**`` (ma

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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…