示例#1
0
文件: core.py 项目: Ajami712/cobrapy
def abs(A):
    F = cern_abs
    if isinstance(A,float):
        return java.lang.Math.abs(A)
    else:
        X = A._M.assign(F)
        return ndarray(X);
示例#2
0
def ones(shape, dtype=float, order='C'):
    """Return a new array of given shape and type, filled with ones.
    
     
    See Also
    --------
    zeros
    
    Examples
    --------
    >>> numjy.ones(5)
    array([ 1.,  1.,  1.,  1.,  1.])
    
    >>> numjy.ones((5,), dtype=numjy.int)
    array([1, 1, 1, 1, 1])
    
    >>> numjy.ones((2, 1))
    array([[ 1.],
           [ 1.]])
    
    >>> s = (2,2)
    >>> numjy.ones(s)
    array([[ 1.,  1.],
           [ 1.,  1.]])"""
    return (ndarray(shape[0], shape[1], 1))
示例#3
0
def abs(A):
    F = cern_abs
    if isinstance(A, float):
        return java.lang.Math.abs(A)
    else:
        X = A._M.assign(F)
        return ndarray(X)
示例#4
0
文件: core.py 项目: Ajami712/cobrapy
def ones(shape, dtype=float, order='C'):
    """Return a new array of given shape and type, filled with ones.
    
     
    See Also
    --------
    zeros
    
    Examples
    --------
    >>> numjy.ones(5)
    array([ 1.,  1.,  1.,  1.,  1.])
    
    >>> numjy.ones((5,), dtype=numjy.int)
    array([1, 1, 1, 1, 1])
    
    >>> numjy.ones((2, 1))
    array([[ 1.],
           [ 1.]])
    
    >>> s = (2,2)
    >>> numjy.ones(s)
    array([[ 1.,  1.],
           [ 1.,  1.]])"""
    return(ndarray(shape[0], shape[1], 1))
示例#5
0
文件: core.py 项目: Ajami712/cobrapy
def solve_LR(A, B):
    T = A._M.copy()
    F = LUDecomposition(T);
    if isinstance(A, ndarray) and isinstance(B, float):
            return F.solve(B);
    elif isinstance(A, ndarray) and isinstance(B, ndarray):
        C = F.solve(B._M);
        return ndarray(C)
示例#6
0
def solve_LR(A, B):
    T = A._M.copy()
    F = LUDecomposition(T)
    if isinstance(A, ndarray) and isinstance(B, float):
        return F.solve(B)
    elif isinstance(A, ndarray) and isinstance(B, ndarray):
        C = F.solve(B._M)
        return ndarray(C)
示例#7
0
def vstack(tup):
    """     Stack arrays in sequence vertically (row wise).
    
    Take a sequence of arrays and stack them vertically to make a single
    array. Rebuild arrays divided by `vsplit`.
    Parameters
    ----------
    tup : sequence of ndarrays
        Tuple containing arrays to be stacked. The arrays must have the same
        shape along all but the first axis.
    Returns
    -------
    stacked : ndarray
        The array formed by stacking the given arrays.
    See Also
    --------
    hstack : Stack arrays in sequence horizontally (column wise).
    dstack : Stack arrays in sequence depth wise (along third dimension).
    concatenate : Join a sequence of arrays together.
    vsplit : Split array into a list of multiple sub-arrays vertically.
    
    
    Notes
    -----
    Equivalent to ``np.concatenate(tup, axis=0)``
    
    Examples
    --------
    >>> a = np.array([1, 2, 3])
    >>> b = np.array([2, 3, 4])
    >>> np.vstack((a,b))
    array([[1, 2, 3],
           [2, 3, 4]])
    
    >>> a = np.array([[1], [2], [3]])
    >>> b = np.array([[2], [3], [4]])
    >>> np.vstack((a,b))
    array([[1],
           [2],
           [3],
           [2],
           [3],
           [4]])

           """
    if isinstance(tup[0], sdarray):
        matrix_factory = DoubleFactory2D.sparse
    else:
        #Allow for the case that python lists or tuples are fed to the function
        tup = map(array, tup)
        matrix_factory = DoubleFactory2D.dense

    stacked_matrix = tup[0]._M
    for the_array in tup[1:]:
        stacked_matrix = matrix_factory.appendRows(stacked_matrix,
                                                   the_array._M)
    return (ndarray(stacked_matrix))
示例#8
0
文件: core.py 项目: Ajami712/cobrapy
def vstack(tup):
    """     Stack arrays in sequence vertically (row wise).
    
    Take a sequence of arrays and stack them vertically to make a single
    array. Rebuild arrays divided by `vsplit`.
    Parameters
    ----------
    tup : sequence of ndarrays
        Tuple containing arrays to be stacked. The arrays must have the same
        shape along all but the first axis.
    Returns
    -------
    stacked : ndarray
        The array formed by stacking the given arrays.
    See Also
    --------
    hstack : Stack arrays in sequence horizontally (column wise).
    dstack : Stack arrays in sequence depth wise (along third dimension).
    concatenate : Join a sequence of arrays together.
    vsplit : Split array into a list of multiple sub-arrays vertically.
    
    
    Notes
    -----
    Equivalent to ``np.concatenate(tup, axis=0)``
    
    Examples
    --------
    >>> a = np.array([1, 2, 3])
    >>> b = np.array([2, 3, 4])
    >>> np.vstack((a,b))
    array([[1, 2, 3],
           [2, 3, 4]])
    
    >>> a = np.array([[1], [2], [3]])
    >>> b = np.array([[2], [3], [4]])
    >>> np.vstack((a,b))
    array([[1],
           [2],
           [3],
           [2],
           [3],
           [4]])

           """
    if isinstance(tup[0], sdarray):
        matrix_factory = DoubleFactory2D.sparse
    else:
        #Allow for the case that python lists or tuples are fed to the function
        tup = map(array, tup)
        matrix_factory = DoubleFactory2D.dense

    stacked_matrix = tup[0]._M
    for the_array in tup[1:]:
        stacked_matrix = matrix_factory.appendRows(stacked_matrix, the_array._M)
    return(ndarray(stacked_matrix))
示例#9
0
def solve(A, B):
    F = Algebra()
    if isinstance(A, ndarray) and isinstance(B, float):
        return F.solve(A._M, B)
    elif isinstance(B, ndarray) and isinstance(A, float):
        return F.solve(A, B._M)
    elif isinstance(A, ndarray) and isinstance(B, ndarray):
        return ndarray(F.solve(A._M, B._M))
    else:
        return A / B
示例#10
0
文件: core.py 项目: Ajami712/cobrapy
def solve_transpose(A, B):
    F = Algebra();
    if isinstance(A, ndarray) and isinstance(B, float):
            return F.solveTranspose(A._M,B);
    elif isinstance(B, ndarray) and  isinstance(A, float):
            return F.solveTranspose(A, B._M);
    elif isinstance(A, ndarray) and isinstance(B, ndarray):
            return ndarray(F.solveTranspose(A._M, B._M));
    else:
        return A / B
示例#11
0
def hstack(tup):
    """
    Stack arrays in sequence horizontally (column wise).

    Take a sequence of arrays and stack them horizontally to make a single array. Rebuild arrays divided by hsplit.

    Parameters:
    tup : sequence of ndarrays
    All arrays must have the same shape along all but the second axis.
    Returns:
    stacked : ndarray
    The array formed by stacking the given arrays.
    See also
    vstack
    Stack arrays in sequence vertically (row wise).
    dstack
    Stack arrays in sequence depth wise (along third axis).
    concatenate
    Join a sequence of arrays together.
    hsplit
    Split array along second axis.
    Notes

    Equivalent to np.concatenate(tup, axis=1)

    Examples

    >>> a = np.array((1,2,3))
    >>> b = np.array((2,3,4))
    >>> np.hstack((a,b))
    array([1, 2, 3, 2, 3, 4])
    >>> a = np.array([[1],[2],[3]])
    >>> b = np.array([[2],[3],[4]])
    >>> np.hstack((a,b))
    array([[1, 2],
           [2, 3],
           [3, 4]])
    """

    if isinstance(tup[0], sdarray):
        matrix_factory = DoubleFactory2D.sparse
    else:
        tup = map(array, tup)
        matrix_factory = DoubleFactory2D.dense

    hstacked_matrix = tup[0]._M
    for the_array in tup[1:]:
        hstacked_matrix = matrix_factory.appendColumns(hstacked_matrix,
                                                       the_array._M)
    return (ndarray(hstacked_matrix))
示例#12
0
文件: core.py 项目: Ajami712/cobrapy
def hstack(tup):
    """
    Stack arrays in sequence horizontally (column wise).

    Take a sequence of arrays and stack them horizontally to make a single array. Rebuild arrays divided by hsplit.

    Parameters:
    tup : sequence of ndarrays
    All arrays must have the same shape along all but the second axis.
    Returns:
    stacked : ndarray
    The array formed by stacking the given arrays.
    See also
    vstack
    Stack arrays in sequence vertically (row wise).
    dstack
    Stack arrays in sequence depth wise (along third axis).
    concatenate
    Join a sequence of arrays together.
    hsplit
    Split array along second axis.
    Notes

    Equivalent to np.concatenate(tup, axis=1)

    Examples

    >>> a = np.array((1,2,3))
    >>> b = np.array((2,3,4))
    >>> np.hstack((a,b))
    array([1, 2, 3, 2, 3, 4])
    >>> a = np.array([[1],[2],[3]])
    >>> b = np.array([[2],[3],[4]])
    >>> np.hstack((a,b))
    array([[1, 2],
           [2, 3],
           [3, 4]])
    """

    if isinstance(tup[0], sdarray):
        matrix_factory = DoubleFactory2D.sparse
    else:
        tup = map(array, tup)
        matrix_factory = DoubleFactory2D.dense

    hstacked_matrix = tup[0]._M
    for the_array in tup[1:]:
        hstacked_matrix = matrix_factory.appendColumns(hstacked_matrix, the_array._M)
    return(ndarray(hstacked_matrix))
示例#13
0
文件: core.py 项目: Ajami712/cobrapy
def transpose(A):
    F = Algebra();
    if isinstance(A,float):
        return A;
    else:
        return ndarray(F.transpose(A._M));
示例#14
0
def cov(A):
    return ndarray(covariance(A._M))
示例#15
0
def cor(A):  # handle multidimensional matrix case
    B = cov(A)
    return ndarray(correlation(B._M))
示例#16
0
文件: core.py 项目: Ajami712/cobrapy
def svd(A):
    X = SingularValueDecomposition(A._M)
    u = X.getU()
    v = X.getV()
    e = X.getS()
    return [ndarray(u), ndarray(e), ndarray(v)]
示例#17
0
def svd(A):
    X = SingularValueDecomposition(A._M)
    u = X.getU()
    v = X.getV()
    e = X.getS()
    return [ndarray(u), ndarray(e), ndarray(v)]
示例#18
0
文件: core.py 项目: Ajami712/cobrapy
def cor(A):  # handle multidimensional matrix case
    B = cov(A);
    return  ndarray(correlation(B._M))
示例#19
0
文件: core.py 项目: Ajami712/cobrapy
def cov(A):
    return ndarray(covariance(A._M))
示例#20
0
def transpose(A):
    F = Algebra()
    if isinstance(A, float):
        return A
    else:
        return ndarray(F.transpose(A._M))
示例#21
0
文件: core.py 项目: Ajami712/cobrapy
def inverse(A):
    F = Algebra();
    x=F.inverse(A._M);
    return ndarray(x)
示例#22
0
def inverse(A):
    F = Algebra()
    x = F.inverse(A._M)
    return ndarray(x)
示例#23
0
文件: core.py 项目: Ajami712/cobrapy
def inverse(A):
    F = Algebra();
    x=F.inverse(A._M);
    return ndarray(x)


def eig(A):
        # check that _M is square
    try:
        E = EigenvalueDecomposition(A._M);
        U = E.getV();
        eigs = E.getD();
    except PyValueException, e:
        print e;
        raise PyValueException,"Error in eig, check warnings()";  
    return [ndarray(eigs),ndarray(U)];

def solve(A, B):
    F = Algebra();
    if isinstance(A, ndarray) and isinstance(B, float):
            return F.solve(A._M, B);
    elif isinstance(B, ndarray) and  isinstance(A, float):
            return F.solve(A, B._M);
    elif isinstance(A,ndarray) and isinstance(B, ndarray):
            return ndarray(F.solve(A._M, B._M))
    else:
        return A / B

def solve_transpose(A, B):
    F = Algebra();
    if isinstance(A, ndarray) and isinstance(B, float):
示例#24
0
def inverse(A):
    F = Algebra()
    x = F.inverse(A._M)
    return ndarray(x)


def eig(A):
    # check that _M is square
    try:
        E = EigenvalueDecomposition(A._M)
        U = E.getV()
        eigs = E.getD()
    except PyValueException, e:
        print e
        raise PyValueException, "Error in eig, check warnings()"
    return [ndarray(eigs), ndarray(U)]


def solve(A, B):
    F = Algebra()
    if isinstance(A, ndarray) and isinstance(B, float):
        return F.solve(A._M, B)
    elif isinstance(B, ndarray) and isinstance(A, float):
        return F.solve(A, B._M)
    elif isinstance(A, ndarray) and isinstance(B, ndarray):
        return ndarray(F.solve(A._M, B._M))
    else:
        return A / B


def solve_transpose(A, B):