def mul_shapes(lh_shape, rh_shape):
    """Give the shape resulting from multiplying two shapes.

    Args:
        lh_shape: A (row, col) tuple.
        rh_shape: A (row, col) tuple.

    Returns:
        The shape (row, col) shape of the product.
    """
    if lh_shape == (1, 1):
        return rh_shape
    elif rh_shape == (1, 1):
        return lh_shape
    else:
        if lh_shape[1] != rh_shape[0]:
            raise ValueError("Incompatible dimensions %s %s" % (
                lh_shape, rh_shape))
        return (lh_shape[0], rh_shape[1])