qiskit/quantum_info/operators/quaternion.py
def quaternion_from_axis_rotation(angle, axis):
    """Return quaternion for rotation about given axis.

    Args:
        angle (float): Angle in radians.
        axis (str): Axis for rotation

    Returns:
        Quaternion: Quaternion for axis rotation.

    Raises:
        ValueError: Invalid input axis.
    """
    out = np.zeros(4, dtype=float)
    if axis == 'x':
        out[1] = 1
    elif axis == 'y':
        out[2] = 1
    elif axis == 'z':
        out[3] = 1
    else:
        raise ValueError('Invalid axis input.')
    out *= math.sin(angle/2.0)
    out[0] = math.cos(angle/2.0)
    return Quaternion(out)
def quaternion_from_axis_rotation(angle, axis):
    out = np.zeros(4, dtype=float)
    if axis == 'x':
        out[1] = 1
    elif axis == 'y':
        out[2] = 1
    elif axis == 'z':
        out[3] = 1
    else:
        raise ValueError('Invalid axis input.')
    out *= math.sin(angle/2.0)
    out[0] = math.cos(angle/2.0)
    return Quaternion(out)
def quaternion_from_axis_rotation ( angle , axis ) : out = np . zeros ( 4 , dtype = float ) if axis == 'x' : out [ 1 ] = 1 elif axis == 'y' : out [ 2 ] = 1 elif axis == 'z' : out [ 3 ] = 1 else : raise ValueError ( 'Invalid axis input.' ) out *= math . sin ( angle / 2.0 ) out [ 0 ] = math . cos ( angle / 2.0 ) return Quaternion ( out )
Return quaternion for rotation about given axis.

    Args:
        angle (float): Angle in radians.
        axis (str): Axis for rotation

    Returns:
        Quaternion: Quaternion for axis rotation.

    Raises:
        ValueError: Invalid input axis.
Return quaternion for rotation about given axis .