def canonicalShape(shape):
    """Calculates a *canonical* shape, how the given ``shape`` should
    be presented. The shape is forced to be at least three dimensions,
    with any other trailing dimensions of length 1 ignored.
    """
    shape = list(shape)
    for i in reversed(range(len(shape))):
        if shape[i] == 1:
            shape = shape[:i]
        else:
            break
    if len(shape) < 3:
        shape = shape + [1] * (3 - len(shape))
    return shape
