stats.py 文件源码

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

项目:BigBrotherBot-For-UrT43 作者: ptitbigorneau 项目源码 文件源码
def atvar(a,limits=None,inclusive=(1,1)):
    """
   Returns the sample variance of values in an array, (i.e., using N-1),
   ignoring values strictly outside the sequence passed to 'limits'.  
   Note: either limit in the sequence, or the value of limits itself,
   can be set to None.  The inclusive list/tuple determines whether the lower
   and upper limiting bounds (respectively) are open/exclusive (0) or
   closed/inclusive (1). ASSUMES A FLAT ARRAY (OR ELSE PREFLATTENS).

   Usage:   atvar(a,limits=None,inclusive=(1,1))
   """
    a = a.astype(N.float_)
    if limits == None or limits == [None,None]:
        return avar(a)
    assert type(limits) in [ListType,TupleType,N.ndarray], "Wrong type for limits in atvar"
    if inclusive[0]:    lowerfcn = N.greater_equal
    else:               lowerfcn = N.greater
    if inclusive[1]:    upperfcn = N.less_equal
    else:               upperfcn = N.less
    if limits[0] > N.maximum.reduce(N.ravel(a)) or limits[1] < N.minimum.reduce(N.ravel(a)):
        raise ValueError, "No array values within given limits (atvar)."
    elif limits[0]==None and limits[1]<>None:
        mask = upperfcn(a,limits[1])
    elif limits[0]<>None and limits[1]==None:
        mask = lowerfcn(a,limits[0])
    elif limits[0]<>None and limits[1]<>None:
        mask = lowerfcn(a,limits[0])*upperfcn(a,limits[1])

    a = N.compress(mask,a)  # squish out excluded values
    return avar(a)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号