Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
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)
    return Poly(A, P.dim, shape, P.dtype)
Exemplo n.º 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