normalize.py 文件源码

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

项目:loompy 作者: linnarsson-lab 项目源码 文件源码
def normalize_attr_values(a: Any) -> np.ndarray:
    """
    Take all kinds of input values and validate/normalize them.

    Args:
        a   List, tuple, np.matrix, np.ndarray or sparse matrix
            Elements can be strings, numbers or bools

    Returns
        a_normalized    An np.ndarray with elements either float64 or unicode string objects

    Remarks:
        This method should be used to prepare the values to be stored in the HDF5 file. You should not
        return the values to the caller; for that, use materialize_attr_values()
    """
    scalar = False
    if np.isscalar(a):
        a = np.array([a])
        scalar = True
    arr = normalize_attr_array(a)
    if np.issubdtype(arr.dtype, np.integer) or np.issubdtype(arr.dtype, np.floating):
        pass  # We allow all these types
    elif np.issubdtype(arr.dtype, np.character) or np.issubdtype(arr.dtype, np.object_):
        arr = normalize_attr_strings(arr)
    elif np.issubdtype(arr.dtype, np.bool_):
        arr = arr.astype('ubyte')
    if scalar:
        return arr[0]
    else:
        return arr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号