eigenfunctions.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:pyinduct 作者: pyinduct 项目源码 文件源码
def return_real_part(to_return):
    """
    Check if the imaginary part of to_return vanishes
    and return the real part
    :param to_return:
    :return:
    """
    if not isinstance(to_return, (Number, list, np.ndarray)):
        raise TypeError
    if isinstance(to_return, (list, np.ndarray)):
        if not all([isinstance(num, Number) for num in to_return]):
            raise TypeError

    maybe_real = np.atleast_1d(np.real_if_close(to_return))

    if maybe_real.dtype == 'complex':
        raise ValueError("Something goes wrong, imaginary part does not vanish")
    else:
        if maybe_real.shape == (1,):
            maybe_real = maybe_real[0]
        return maybe_real
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号