Skip to content

array reshaper #7

@darienmorrow

Description

@darienmorrow
def array_reshaper(A, B):
    """Checks to see if arrays are same shape, if not, increase dimensionality of array until shapes match.
    
    Parameters
    ----------
    A : array
    B : array
    
    Returns
    -------
    A : array
        Reshaped copy of input array
    B : array
        Reshaped copy of input array
    
    """
    
    A = A.copy()
    B = B.copy()
    for a,b in zip(A.shape, B.shape):
        if a == 1 or b == 1:
            continue
        if a != b:
            raise ValueError
    a_sh = list(A.shape)
    b_sh = list(B.shape)
    while len(a_sh) < len(b_sh):
        a_sh.append(1)
    while len(b_sh) < len(a_sh):
        b_sh.append(1)
    A = np.reshape(A, a_sh)
    B = np.reshape(B, b_sh)
    return A, B

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions