def cross(a,b):
    """Cross product between a 3-vector or a 2-vector"""
    if len(a)!=len(b):
        raise RuntimeError('Vector dimensions not 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 RuntimeError('Vectors must be 2D or 3D')