def cross(a, b):
    """Cross product between a 3-vector or a 2-vector"""
    assert len(a) == len(b), 'Vector dimensions should be equal'
    if len(a) == 3:
        return (
            a[1] * b[2] - a[2] * b[1],
            a[2] * b[0] - a[0] * b[2],
            a[0] * b[1] - a[1] * b[0])
    elif len(a) == 2:
        return a[0] * b[1] - a[1] * b[0]
    else:
        raise ValueError('Vectors must be 2D or 3D')