当前位置: 首页>>代码示例>>Python>>正文


Python defmatrix.asmatrix方法代码示例

本文整理汇总了Python中numpy.matrixlib.defmatrix.asmatrix方法的典型用法代码示例。如果您正苦于以下问题:Python defmatrix.asmatrix方法的具体用法?Python defmatrix.asmatrix怎么用?Python defmatrix.asmatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.matrixlib.defmatrix的用法示例。


在下文中一共展示了defmatrix.asmatrix方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: eye

# 需要导入模块: from numpy.matrixlib import defmatrix [as 别名]
# 或者: from numpy.matrixlib.defmatrix import asmatrix [as 别名]
def eye(n,M=None, k=0, dtype=float):
    """
    Return a matrix with ones on the diagonal and zeros elsewhere.

    Parameters
    ----------
    n : int
        Number of rows in the output.
    M : int, optional
        Number of columns in the output, defaults to `n`.
    k : int, optional
        Index of the diagonal: 0 refers to the main diagonal,
        a positive value refers to an upper diagonal,
        and a negative value to a lower diagonal.
    dtype : dtype, optional
        Data-type of the returned matrix.

    Returns
    -------
    I : matrix
        A `n` x `M` matrix where all elements are equal to zero,
        except for the `k`-th diagonal, whose values are equal to one.

    See Also
    --------
    numpy.eye : Equivalent array function.
    identity : Square identity matrix.

    Examples
    --------
    >>> import numpy.matlib
    >>> np.matlib.eye(3, k=1, dtype=float)
    matrix([[ 0.,  1.,  0.],
            [ 0.,  0.,  1.],
            [ 0.,  0.,  0.]])

    """
    return asmatrix(np.eye(n, M, k, dtype)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:40,代码来源:matlib.py

示例2: eye

# 需要导入模块: from numpy.matrixlib import defmatrix [as 别名]
# 或者: from numpy.matrixlib.defmatrix import asmatrix [as 别名]
def eye(n,M=None, k=0, dtype=float, order='C'):
    """
    Return a matrix with ones on the diagonal and zeros elsewhere.

    Parameters
    ----------
    n : int
        Number of rows in the output.
    M : int, optional
        Number of columns in the output, defaults to `n`.
    k : int, optional
        Index of the diagonal: 0 refers to the main diagonal,
        a positive value refers to an upper diagonal,
        and a negative value to a lower diagonal.
    dtype : dtype, optional
        Data-type of the returned matrix.
    order : {'C', 'F'}, optional
        Whether the output should be stored in row-major (C-style) or
        column-major (Fortran-style) order in memory.

        .. versionadded:: 1.14.0

    Returns
    -------
    I : matrix
        A `n` x `M` matrix where all elements are equal to zero,
        except for the `k`-th diagonal, whose values are equal to one.

    See Also
    --------
    numpy.eye : Equivalent array function.
    identity : Square identity matrix.

    Examples
    --------
    >>> import numpy.matlib
    >>> np.matlib.eye(3, k=1, dtype=float)
    matrix([[ 0.,  1.,  0.],
            [ 0.,  0.,  1.],
            [ 0.,  0.,  0.]])

    """
    return asmatrix(np.eye(n, M=M, k=k, dtype=dtype, order=order)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:45,代码来源:matlib.py

示例3: rand

# 需要导入模块: from numpy.matrixlib import defmatrix [as 别名]
# 或者: from numpy.matrixlib.defmatrix import asmatrix [as 别名]
def rand(*args):
    """
    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)``.

    Parameters
    ----------
    \\*args : Arguments
        Shape of the output.
        If given as N integers, each integer specifies the size of one
        dimension.
        If given as a tuple, this tuple gives the complete shape.

    Returns
    -------
    out : ndarray
        The matrix of random values with shape given by `\\*args`.

    See Also
    --------
    randn, numpy.random.rand

    Examples
    --------
    >>> import numpy.matlib
    >>> np.matlib.rand(2, 3)
    matrix([[ 0.68340382,  0.67926887,  0.83271405],
            [ 0.00793551,  0.20468222,  0.95253525]])       #random
    >>> np.matlib.rand((2, 3))
    matrix([[ 0.84682055,  0.73626594,  0.11308016],
            [ 0.85429008,  0.3294825 ,  0.89139555]])       #random

    If the first argument is a tuple, other arguments are ignored:

    >>> np.matlib.rand((2, 3), 4)
    matrix([[ 0.46898646,  0.15163588,  0.95188261],
            [ 0.59208621,  0.09561818,  0.00583606]])       #random

    """
    if isinstance(args[0], tuple):
        args = args[0]
    return asmatrix(np.random.rand(*args)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:46,代码来源:matlib.py

示例4: randn

# 需要导入模块: from numpy.matrixlib import defmatrix [as 别名]
# 或者: from numpy.matrixlib.defmatrix import asmatrix [as 别名]
def randn(*args):
    """
    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.

    Parameters
    ----------
    \\*args : Arguments
        Shape of the output.
        If given as N integers, each integer specifies the size of one
        dimension. If given as a tuple, this tuple gives the complete shape.

    Returns
    -------
    Z : matrix of floats
        A matrix of floating-point samples drawn from the standard normal
        distribution.

    See Also
    --------
    rand, random.randn

    Notes
    -----
    For random samples from :math:`N(\\mu, \\sigma^2)`, use:

    ``sigma * np.matlib.randn(...) + mu``

    Examples
    --------
    >>> import numpy.matlib
    >>> np.matlib.randn(1)
    matrix([[-0.09542833]])                                 #random
    >>> np.matlib.randn(1, 2, 3)
    matrix([[ 0.16198284,  0.0194571 ,  0.18312985],
            [-0.7509172 ,  1.61055   ,  0.45298599]])       #random

    Two-by-four matrix of samples from :math:`N(3, 6.25)`:

    >>> 2.5 * np.matlib.randn((2, 4)) + 3
    matrix([[ 4.74085004,  8.89381862,  4.09042411,  4.83721922],
            [ 7.52373709,  5.07933944, -2.64043543,  0.45610557]])  #random

    """
    if isinstance(args[0], tuple):
        args = args[0]
    return asmatrix(np.random.randn(*args)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:51,代码来源:matlib.py

示例5: repmat

# 需要导入模块: from numpy.matrixlib import defmatrix [as 别名]
# 或者: from numpy.matrixlib.defmatrix import asmatrix [as 别名]
def repmat(a, m, n):
    """
    Repeat a 0-D to 2-D array or matrix MxN times.

    Parameters
    ----------
    a : array_like
        The array or matrix to be repeated.
    m, n : int
        The number of times `a` is repeated along the first and second axes.

    Returns
    -------
    out : ndarray
        The result of repeating `a`.

    Examples
    --------
    >>> 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]])

    """
    a = asanyarray(a)
    ndim = a.ndim
    if ndim == 0:
        origrows, origcols = (1, 1)
    elif ndim == 1:
        origrows, origcols = (1, a.shape[0])
    else:
        origrows, origcols = a.shape
    rows = origrows * m
    cols = origcols * n
    c = a.reshape(1, a.size).repeat(m, 0).reshape(rows, origcols).repeat(n, 0)
    return c.reshape(rows, cols) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:51,代码来源:matlib.py


注:本文中的numpy.matrixlib.defmatrix.asmatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。