コード例 #1
0
ファイル: wrapper.py プロジェクト: nixnfg/integrated
def reshape(a, shape):
    """
Reshape the shape of a shapeable quantity

Parameters
----------
a : Poly, frac, array_like
    Shapeable input quantity
shape : tuple
    The polynomials new shape. Must be compatible with the
    number of elements in `A`.

Returns
-------
Q : Poly, frac, array_like
    Same type as `A`.

Examples
--------
>>> P = cp.prange(6)
>>> print P
[1, q0, q0^2, q0^3, q0^4, q0^5]
>>> print cp.reshape(P, (2,3))
[[1, q0, q0^2], [q0^3, q0^4, q0^5]]
    """
    if isinstance(a, (np.ndarray, float, int, long)):
        return np.reshape(a, shape)

    elif isinstance(a, f.frac):
        return f.reshape(a, shape)

    elif isinstance(a, p.Poly):
        return p.reshape(a, shape)
    raise NotImplementedError
コード例 #2
0
ファイル: wrapper.py プロジェクト: apetcho/chaospy
def reshape(a, shape):
    """
Reshape the shape of a shapeable quantity

Parameters
----------
a : Poly, frac, array_like
    Shapeable input quantity
shape : tuple
    The polynomials new shape. Must be compatible with the
    number of elements in `A`.

Returns
-------
Q : Poly, frac, array_like
    Same type as `A`.

Examples
--------
>>> P = cp.prange(6)
>>> print P
[1, q0, q0^2, q0^3, q0^4, q0^5]
>>> print cp.reshape(P, (2,3))
[[1, q0, q0^2], [q0^3, q0^4, q0^5]]
    """
    if isinstance(a, (np.ndarray, float, int, long)):
        return np.reshape(a, shape)

    elif isinstance(a, f.frac):
        return f.reshape(a, shape)

    elif isinstance(a, p.Poly):
        return p.reshape(a, shape)
    raise NotImplementedError
コード例 #3
0
ファイル: base.py プロジェクト: sjhernes/chaospy
def reshape(P, shape):

    A = P.A.copy()
    if P.dtype==f.frac:
        for key in P.keys:
            A[key] = f.reshape(A[key], shape)
        return Poly(A, P.dim, shape, f.frac)

    for key in P.keys:
        A[key] = np.reshape(A[key], shape)
    return Poly(A, P.dim, shape, P.dtype)
コード例 #4
0
def reshape(P, shape):

    A = P.A.copy()
    if P.dtype == f.frac:
        for key in P.keys:
            A[key] = f.reshape(A[key], shape)
        return Poly(A, P.dim, shape, f.frac)

    for key in P.keys:
        A[key] = np.reshape(A[key], shape)
    out = Poly(A, P.dim, shape, P.dtype)
    return out