Пример #1
0
def range(min, max, step=None):
    """ Values between min and max by step.

    If no value is provided, step is set to 1.
    """
    if step is None:
        return asmatrix(S.arange(min, max + 1))
    else:
        return asmatrix(S.arange(min, max + step, step))
Пример #2
0
def unit(r, c=None):
    """Identity matrix.

     If r and c are numbers, it returns a (r, c) matrix,
    r and c being converted to integers when needed.

    If r is a (m, n) matrix, it returns an (m, n) matrix. 
    
    """
    try:
        return asmatrix(N.eye(r, c))
    except TypeError:
        return asmatrix(N.eye(r.shape[0], r.shape[1]))
Пример #3
0
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
    --------
    eye : Equivalent array function
    matlib.identity : Square identity matrix

    Notes
    -----
    For more detailed docuemtation, see the docstring of the equivalent
    array function ``np.eye``.

    """
    return asmatrix(np.eye(n,M,k,dtype))
Пример #4
0
def diag(ma):
    """Diagonal matrix with ma on the diagonal.

    ma needs to be (1, k) or (k, 1).
    """
    EXC._assertVectorOrScalar(asmatrix(ma))
    ma = N.mat(ma)
    return S.diagflat(ma)
Пример #5
0
def toeplitz(ma, cm=None):
    """
    Symmetric Toeplitz matrix.

    ma is a (k, 1) or (1, k) matrix.

    The Toeplitz matrix is of dimension (cm, cm)
    if cm is provided. Otherwise, it is (k, k)
    """
    ma = asmatrix(ma)
    EXC._assertVectorOrScalar(ma)
    if type(cm) == None:
        return asmatrix(L.basic.toeplitz(ma))
    else:
        m = ma.flatten()
        if cm is None:
            return asmatrix(L.basic.toeplitz(ma))
        else:
            if cm >= m.shape[1]: 
                n = cbind(zeros(N.mat(1), cm -  m.shape[1]))
                return asmatrix(L.basic.toeplitz(n))
            else:
                return asmatrix(L.basic.toeplitz(m[0:cm, 0:cm]))
Пример #6
0
def randn(*args):
    if isinstance(args[0], tuple):
       args = args[0]
    return asmatrix(N.random.randn(*args))
Пример #7
0
def eye(n,M=None, k=0, dtype=float):
    return asmatrix(N.eye(n,M,k,dtype))
Пример #8
0
            height = 1
            addon = N.resize(addon,[height, source.shape[1]])
        else:
            height = source.shape[0]
        if len(addon) < len(source):
            addon = N.resize(addon,[addon.shape[0], source.shape[1]])
        elif len(source) < len(addon):
            source = N.resize(source,[source.shape[0], addon.shape[1]])
        source = N.concatenate((source,addon),0)
    return source

    



##--------------------------------------------------------------------
## MAIN
##--------------------------------------------------------------------

if __name__ == "__main__":

    x = asmatrix(N.random.normal(5,2,(4,1)))
    d = diag(x)
    print(x)
    
    
    
	
	

Пример #9
0
def randn(*args):
    if isinstance(args[0], tuple):
        args = args[0]
    return asmatrix(np.random.randn(*args))
Пример #10
0
def eye(n, M=None, k=0, dtype=float):
    return asmatrix(np.eye(n, M, k, dtype))