util.py 文件源码

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

项目:prysm 作者: brandondube 项目源码 文件源码
def guarantee_array(variable):
    ''' Guarantees that a varaible is a numpy ndarray and supports -, *, +, and other operators

    Args:
        variable (`number` or `numpy.ndarray`): variable to coalesce

    Returns:
        (type).  Which supports * / and other operations with arrays

    '''
    if type(variable) in [float, np.ndarray, np.int32, np.int64, np.float32, np.float64, np.complex64, np.complex128]:
        return variable
    elif type(variable) is int:
        return float(variable)
    elif type(variable) is list:
        return np.asarray(variable)
    else:
        raise ValueError(f'variable is of invalid type {type(variable)}')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号