def safe_mean(values): """ Returns mean value discarding non finite values """ valid_values = [] for v in values: if numpy.isfinite(v): valid_values.append(v) return numpy.mean(valid_values), numpy.std(valid_values)
def safe_mean_vector(vectors): """ Returns mean profile discarding non finite values """ # if only one vector, avg = itself if len(vectors) == 1: return vectors[0], numpy.zeros(len(vectors[0])) # Takes the vector length form the first item length = len(vectors[0]) safe_mean = [] safe_std = [] for pos in xrange(length): pos_mean = [] for v in vectors: if numpy.isfinite(v[pos]): pos_mean.append(v[pos]) safe_mean.append(numpy.mean(pos_mean)) safe_std.append(numpy.std(pos_mean)) return safe_mean, safe_std
def safe_mean_vector(vectors): """ Returns mean profile discarding non finite values """ # if only one vector, avg = itself if len(vectors)==1: return vectors[0], numpy.zeros(len(vectors[0])) # Takes the vector length form the first item length = len(vectors[0]) safe_mean = [] safe_std = [] for pos in xrange(length): pos_mean = [] for v in vectors: if numpy.isfinite(v[pos]): pos_mean.append(v[pos]) safe_mean.append(numpy.mean(pos_mean)) safe_std.append(numpy.std(pos_mean)) return safe_mean, safe_std
def get_mean_vector(vlist): a = numpy.array(vlist) return numpy.mean(a, 0)
def get_mean_vector(vlist): a = numpy.array(vlist) return numpy.mean(a,0)