Undocumented
Function | empty |
Return a new matrix of given shape and type, without initializing entries. |
Function | eye |
Return a matrix with ones on the diagonal and zeros elsewhere. |
Function | identity |
Returns the square identity matrix of given size. |
Function | ones |
Matrix of ones. |
Function | rand |
Return a matrix of random values with given shape. |
Function | randn |
Return a random matrix with data from the "standard normal" distribution. |
Function | repmat |
Repeat a 0-D to 2-D array or matrix MxN times. |
Function | zeros |
Return a matrix of given shape and type, filled with zeros. |
Return a new matrix of given shape and type, without initializing entries.
empty_like, zeros
empty
, unlike zeros
, does not set the matrix values to zero,
and may therefore be marginally faster. On the other hand, it requires
the user to manually set all the values in the array, and should be
used with caution.
>>> import numpy.matlib >>> np.matlib.empty((2, 2)) # filled with random data matrix([[ 6.76425276e-320, 9.79033856e-307], # random [ 7.39337286e-309, 3.22135945e-309]]) >>> np.matlib.empty((2, 2), dtype=int) matrix([[ 6600475, 0], # random [ 6586976, 22740995]])
Return a matrix with ones on the diagonal and zeros elsewhere.
n
.Whether the output should be stored in row-major (C-style) or column-major (Fortran-style) order in memory.
n
x M
matrix where all elements are equal to zero,
except for the k
-th diagonal, whose values are equal to one.numpy.eye : Equivalent array function. identity : Square identity matrix.
>>> import numpy.matlib >>> np.matlib.eye(3, k=1, dtype=float) matrix([[0., 1., 0.], [0., 0., 1.], [0., 0., 0.]])
Returns the square identity matrix of given size.
n
x n
matrix with its main diagonal set to one,
and all other elements zero.numpy.identity : Equivalent array function. matlib.eye : More general matrix identity function.
>>> import numpy.matlib >>> np.matlib.identity(3, dtype=int) matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
Matrix of ones.
Return a matrix of given shape and type, filled with ones.
ones : Array of ones. matlib.zeros : Zero matrix.
If shape
has length one i.e. (N,), or is a scalar N,
out
becomes a single row matrix of shape (1,N).
>>> np.matlib.ones((2,3)) matrix([[1., 1., 1.], [1., 1., 1.]])
>>> np.matlib.ones(2) matrix([[1., 1.]])
Return a matrix of random values with given shape.
Create a matrix of the given shape and propagate it with random samples from a uniform distribution over [0, 1).
*args
.randn, numpy.random.RandomState.rand
>>> np.random.seed(123) >>> import numpy.matlib >>> np.matlib.rand(2, 3) matrix([[0.69646919, 0.28613933, 0.22685145], [0.55131477, 0.71946897, 0.42310646]]) >>> np.matlib.rand((2, 3)) matrix([[0.9807642 , 0.68482974, 0.4809319 ], [0.39211752, 0.34317802, 0.72904971]])
If the first argument is a tuple, other arguments are ignored:
>>> np.matlib.rand((2, 3), 4) matrix([[0.43857224, 0.0596779 , 0.39804426], [0.73799541, 0.18249173, 0.17545176]])
Return a random matrix with data from the "standard normal" distribution.
randn
generates a matrix filled with random floats sampled from a
univariate "normal" (Gaussian) distribution of mean 0 and variance 1.
rand, numpy.random.RandomState.randn
For random samples from N(μ, σ2), use:
sigma * np.matlib.randn(...) + mu
>>> np.random.seed(123) >>> import numpy.matlib >>> np.matlib.randn(1) matrix([[-1.0856306]]) >>> np.matlib.randn(1, 2, 3) matrix([[ 0.99734545, 0.2829785 , -1.50629471], [-0.57860025, 1.65143654, -2.42667924]])
Two-by-four matrix of samples from N(3, 6.25):
>>> 2.5 * np.matlib.randn((2, 4)) + 3 matrix([[1.92771843, 6.16484065, 0.83314899, 1.30278462], [2.76322758, 6.72847407, 1.40274501, 1.8900451 ]])
Repeat a 0-D to 2-D array or matrix MxN times.
a
is repeated along the first and second axes.a
.>>> import numpy.matlib >>> a0 = np.array(1) >>> np.matlib.repmat(a0, 2, 3) array([[1, 1, 1], [1, 1, 1]])
>>> a1 = np.arange(4) >>> np.matlib.repmat(a1, 2, 2) array([[0, 1, 2, 3, 0, 1, 2, 3], [0, 1, 2, 3, 0, 1, 2, 3]])
>>> a2 = np.asmatrix(np.arange(6).reshape(2, 3)) >>> np.matlib.repmat(a2, 2, 3) matrix([[0, 1, 2, 0, 1, 2, 0, 1, 2], [3, 4, 5, 3, 4, 5, 3, 4, 5], [0, 1, 2, 0, 1, 2, 0, 1, 2], [3, 4, 5, 3, 4, 5, 3, 4, 5]])
Return a matrix of given shape and type, filled with zeros.
numpy.zeros : Equivalent array function. matlib.ones : Return a matrix of ones.
If shape
has length one i.e. (N,), or is a scalar N,
out
becomes a single row matrix of shape (1,N).
>>> import numpy.matlib >>> np.matlib.zeros((2, 3)) matrix([[0., 0., 0.], [0., 0., 0.]])
>>> np.matlib.zeros(2) matrix([[0., 0.]])