本文整理汇总了Python中numpy.percentile函数的典型用法代码示例。如果您正苦于以下问题:Python percentile函数的具体用法?Python percentile怎么用?Python percentile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了percentile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iqr
def iqr(data):
return ",".join(
(
digits.format(numpy.percentile(data[column], 75) - numpy.percentile(data[column], 25))
for column in data.columns
)
)
示例2: _auto_limits
def _auto_limits(self):
if self.component_data is None:
return
exclude = (100 - self.percentile) / 2.
# For subsets in 'data' mode, we want to compute the limits based on
# the full dataset, not just the subset.
if isinstance(self.data, Subset):
data_values = self.data.data[self.component_id]
else:
data_values = self.data[self.component_id]
try:
lower = np.nanpercentile(data_values, exclude)
upper = np.nanpercentile(data_values, 100 - exclude)
except AttributeError: # Numpy < 1.9
data_values = data_values[~np.isnan(data_values)]
lower = np.percentile(data_values, exclude)
upper = np.percentile(data_values, 100 - exclude)
if isinstance(self.data, Subset):
lower = 0
self.set_limits(lower, upper)
示例3: main
def main(argv):
map_utilizations = []
reduce_utilizations = []
all_utilizations = []
dirname = argv[0]
for filename in os.listdir(dirname):
full_name = os.path.join(dirname, filename)
if os.path.isfile(full_name) and filename.endswith("job_log"):
print "Reading %s" % filename
analyzer = parse_logs.Analyzer(full_name)
for (id, stage) in analyzer.stages.iteritems():
for task in stage.tasks:
for name, block_device_numbers in task.disk_utilization.iteritems():
if name in ["xvdb", "xvdf"]:
effective_util = 0
if block_device_numbers[0] > 0:
effective_util = (block_device_numbers[1] + block_device_numbers[2]) / block_device_numbers[0]
all_utilizations.append(effective_util)
if task.has_fetch:
reduce_utilizations.append(effective_util)
else:
map_utilizations.append(effective_util)
output_filename = os.path.join(dirname, "disk_utilization_cdf")
f = open(output_filename, "w")
for percent in range(100):
f.write("%s\t%s\t%s\t%s\n" % (percent / 100., numpy.percentile(map_utilizations, percent),
numpy.percentile(reduce_utilizations, percent),
numpy.percentile(all_utilizations, percent)))
f.close()
示例4: get_mean_vmax
def get_mean_vmax():
hostvmaxs = []
hostvmax25s = []
hostvmax75s = []
twentyfifth, fifty, seventyfifth = get_percentile()
rootdir = "/Users/catherinefielder/Documents/Research_Halos/HaloDetail"
for subdir, dirs, files in os.walk(rootdir):
head, tail = os.path.split(subdir)
haloname = tail
for file in files:
if file.endswith("_columnsadded_final"):
values = ascii.read(
os.path.join(subdir, file), format="commented_header"
) # Get full path and access file
hostvmax = values[1]["host_vmax"]
hostvmaxs = np.append(hostvmaxs, hostvmax)
twentyfifth = np.percentile(hostvmaxs, 25)
seventyfifth = np.percentile(hostvmaxs, 75)
for i in range(0, len(hostvmaxs)):
if hostvmaxs[i] >= seventyfifth:
hostvmax75s = np.append(hostvmax75s, hostvmaxs[i])
elif hostvmaxs[i] < twentyfifth:
hostvmax25s = np.append(hostvmax25s, hostvmaxs[i])
else:
continue
sumvmax = np.sum(hostvmaxs)
meanvmax = np.divide(sumvmax, len(hostvmaxs))
mean75 = np.mean(hostvmax75s)
mean25 = np.mean(hostvmax25s)
print "mean"
print meanvmax
print mean75
print mean25
return meanvmax, mean75, mean25
示例5: plot_wavenvelope
def plot_wavenvelope(self, ax, w_start, w_end):
""" This function plots the envelope of the recording.
:param ax: The axis in which you wish to plot.
:param w_start: Start of the best window.
:param w_end: End of the best window.
"""
window_size = int(0.05 * self._sample_rate) # 0.050 are 50 milliseconds for the envelope window!
w = 1.0 * np.ones(window_size) / window_size
envelope = (np.sqrt((np.correlate(self._eod ** 2, w, mode='same') -
np.correlate(self._eod, w, mode='same') ** 2)).ravel()) * np.sqrt(2.)
upper_bound = np.max(envelope) + np.percentile(envelope, 1)
ax.fill_between(self._time[::500], y1=-envelope[::500], y2=envelope[::500], color='purple', alpha=0.5)
ax.plot((w_start, w_start), (-upper_bound, upper_bound), 'k--', linewidth=2)
ax.plot((w_end, w_end), (-upper_bound, upper_bound), 'k--', linewidth=2)
ax.text((w_start + w_end) / 2., upper_bound - np.percentile(envelope, 10), 'Analysis Window',
rotation='horizontal', horizontalalignment='center', verticalalignment='center', fontsize=14)
ax.set_ylim(-upper_bound, upper_bound)
ax.set_xlabel('Time [s]', fontsize=16)
ax.set_ylabel('Signal Amplitude [au]', fontsize=16)
ax.tick_params(axis='both', which='major', labelsize=14)
pass
示例6: getMed
def getMed(x):
if len(x) == 0:
x = np.array([0])
median = np.percentile(x, 50)
sigma_min = median - np.percentile(x, 16)
sigma_max = np.percentile(x, 84) - median
return median, sigma_min, sigma_max
示例7: updateStats
def updateStats(self):
if self.current_layer is not None:
current_attribute = self.dlg.getCurrentAttribute()
if current_attribute >= 0:
attribute = self.layer_attributes[current_attribute]
# check if stats have been calculated before
idx = self.checkValuesAvailable(attribute)
if idx == -1:
self.retrieveAttributeValues(attribute)
idx = len(self.attribute_statistics)-1
stats = self.attribute_statistics[idx]
# calculate stats of selected objects only
select_stats = dict()
if self.current_layer.selectedFeatureCount() > 0:
self.selection_values, self.selection_ids = uf.getFieldValues(self.current_layer, attribute['name'], null=False, selection=True)
sel_values = [val for val in self.selection_values if val != NULL]
select_stats['Number'] = len(sel_values)
select_stats['Mean'] = uf.truncateNumber(np.mean(sel_values))
select_stats['Std Dev'] = uf.truncateNumber(np.std(sel_values))
select_stats['Variance'] = uf.truncateNumber(np.var(sel_values))
select_stats['Median'] = uf.truncateNumber(np.median(sel_values))
select_stats['Minimum'] = np.min(sel_values)
select_stats['Maximum'] = np.max(sel_values)
select_stats['Range'] = uf.truncateNumber(select_stats['Maximum']-select_stats['Minimum'])
select_stats['1st Quart'] = uf.truncateNumber(np.percentile(sel_values,25))
select_stats['3rd Quart'] = uf.truncateNumber(np.percentile(sel_values,75))
select_stats['IQR'] = uf.truncateNumber(select_stats['3rd Quart']-select_stats['1st Quart'])
select_stats['Gini'] = uf.roundNumber(uf.calcGini(sel_values))
else:
self.selection_values = []
self.selection_ids = []
# update the dialog
self.dlg.setStats(stats, select_stats)
示例8: show_bootstrap_statistics
def show_bootstrap_statistics(clf, X, y, features):
num_features = len(features)
coefs = []
for i in range(num_features):
coefs.append([])
for _ in range(BOOTSTRAP_ITERATIONS):
X_sample, y_sample = resample(X, y)
clf.fit(X_sample, y_sample)
for i, c in enumerate(get_normalized_coefs(clf)):
coefs[i].append(c)
poi_index = features.index('POI')
building_index = features.index('Building')
coefs[building_index] = coefs[poi_index]
intervals = []
print()
print('***** Bootstrap statistics *****')
print('{:<20}{:<20}{:<10}{:<10}'.format('Feature', '95% interval', 't-value', 'Pr(>|t|)'))
print()
for i, cs in enumerate(coefs):
values = np.array(cs)
lo = np.percentile(values, 2.5)
hi = np.percentile(values, 97.5)
interval = '({:.3f}, {:.3f})'.format(lo, hi)
tv = np.mean(values) / np.std(values)
pr = (1.0 - t.cdf(x=abs(tv), df=len(values))) * 0.5
stv = '{:.3f}'.format(tv)
spr = '{:.3f}'.format(pr)
print('{:<20}{:<20}{:<10}{:<10}'.format(features[i], interval, stv, spr))
示例9: write_parameters_outputvalues
def write_parameters_outputvalues(self, P):
Mstar, SFR_opt, _ = model.stellar_info_array(self.chain.flatchain_sorted, self.data, self.out['realizations2int'])
column_names = np.transpose(np.array(["P025","P16","P50","P84","P975"], dtype='|S3'))
chain_pars = np.column_stack((self.chain.flatchain_sorted, Mstar, SFR_opt))
# np.mean(chain_pars, axis[0]),
# np.std(chain_pars, axis[0]),
if self.out['calc_intlum']:
SFR_IR = model.sfr_IR(self.int_lums[0]) #check that ['intlum_names'][0] is always L_IR(8-100)
chain_others =np.column_stack((self.int_lums.T, SFR_IR))
outputvalues = np.column_stack((np.transpose(map(lambda v: (v[0],v[1],v[2],v[3],v[4]), zip(*np.percentile(chain_pars, [2.5,16, 50, 84,97.5], axis=0)))),
np.transpose(map(lambda v: (v[0],v[1],v[2],v[3],v[4]), zip(*np.percentile(chain_others, [2.5,16, 50, 84,97.5], axis=0)))) ))
outputvalues_header= ' '.join([ i for i in np.hstack((P.names, 'Mstar', 'SFR_opt', self.out['intlum_names'], 'SFR_IR',))] )
else:
outputvalues = np.column_stack((map(lambda v: (v[1], v[2]-v[1], v[1]-v[0]), zip(*np.percentile(chain_pars, [16, 50, 84], axis=0)))))
outputvalues_header=' '.join( [ i for i in P.names] )
return outputvalues, outputvalues_header
示例10: test_quantile
def test_quantile(self):
from numpy import percentile
q = self.ts.quantile(0.1)
self.assertEqual(q, percentile(self.ts.valid(), 10))
q = self.ts.quantile(0.9)
self.assertEqual(q, percentile(self.ts.valid(), 90))
# object dtype
q = Series(self.ts, dtype=object).quantile(0.9)
self.assertEqual(q, percentile(self.ts.valid(), 90))
# datetime64[ns] dtype
dts = self.ts.index.to_series()
q = dts.quantile(.2)
self.assertEqual(q, Timestamp('2000-01-10 19:12:00'))
# timedelta64[ns] dtype
tds = dts.diff()
q = tds.quantile(.25)
self.assertEqual(q, pd.to_timedelta('24:00:00'))
# GH7661
result = Series([np.timedelta64('NaT')]).sum()
self.assertTrue(result is pd.NaT)
msg = 'percentiles should all be in the interval \\[0, 1\\]'
for invalid in [-1, 2, [0.5, -1], [0.5, 2]]:
with tm.assertRaisesRegexp(ValueError, msg):
self.ts.quantile(invalid)
示例11: ampDiffStats
def ampDiffStats(ampIm1, ampIm2, osIm1, osIm2, exptime=0.0):
stats = np.zeros(shape=(1,),
dtype=statDtype)
a_i = 0
_s1 = np.median(ampIm1) - np.median(osIm1)
_s2 = np.median(ampIm2) - np.median(osIm2)
stats[a_i]['signal'] = signal = (_s1 + _s2)/2
stats[a_i]['npix'] = ampIm1.size
stats[a_i]['sqrtSig'] = np.sqrt(signal)
stats[a_i]['bias'] = (np.median(osIm1) + np.median(osIm2))/2
ampIm = ampIm2.astype('f4') - ampIm1
osIm = osIm2.astype('f4') - osIm1
sig1 = (0.741/np.sqrt(2)) * np.subtract.reduce(np.percentile(ampIm, [75,25]))
sig2 = (0.741/np.sqrt(2)) * np.subtract.reduce(np.percentile(osIm, [75,25]))
_, trusig1, _ = geom.clippedStats(ampIm) / np.sqrt(2)
_, trusig2, _ = geom.clippedStats(osIm) / np.sqrt(2)
stats[a_i]['readnoise'] = sig2
stats[a_i]['readnoiseM'] = trusig2
stats[a_i]['shotnoise'] = sig = np.sqrt(np.abs(sig1**2 - sig2**2))
stats[a_i]['shotnoiseM'] = trusig = np.sqrt(np.abs(trusig1**2 - trusig2**2))
stats[a_i]['gain'] = gain = signal/sig**2
stats[a_i]['gainM'] = signal/trusig**2
stats[a_i]['noise'] = sig2*gain
stats[a_i]['flux'] = signal/exptime if exptime != 0 else 0.0
return stats, ampIm, osIm
示例12: descriptive_stats
def descriptive_stats(array, verbose=True, label='', mean=False, plot=False):
""" Simple statistics from vector.
"""
if mean:
mean_ = np.mean(array)
median = np.median(array)
mini = np.min(array)
maxi = np.max(array)
first_qu = np.percentile(array, 25)
third_qu = np.percentile(array, 75)
if verbose:
if mean:
label += 'min={:.1f} / 1st QU={:.1f} / ave={:.1f} / med={:.1f} / '
label += '3rd QU={:.1f} / max={:.1f}'
print(label.format(mini, first_qu, mean_, median, third_qu, maxi))
else:
label += 'min={:.1f} / 1st QU={:.1f} / med={:.1f} / 3rd QU={:.1f} '
label += '/ max={:.1f}'
print(label.format(mini, first_qu, median, third_qu, maxi))
if plot:
boxplot(array, vert=False, meanline=mean, showfliers=True, sym='.')
if mean:
return mini, first_qu, mean_, median, third_qu, maxi
else:
return mini, first_qu, median, third_qu, maxi
示例13: get_stat_function
def get_stat_function(statistics, perc=None):
# Define personalized functions for binned_statistics
if (statistics == 'mean') | (statistics == 'median'):
stat_func = statistics
elif statistics == 'std':
stat_func = np.std
elif statistics == 'mse':
stat_func = lambda x: np.mean(x**2)
elif statistics == 'frac':
# stat_func = lambda x: 100.0*np.abs(np.mean(x))/(np.abs(np.mean(x)) + np.std(x)) Wrong decomposition
stat_func = lambda x: np.sign(np.mean(x))*100.0*np.mean(x)**2/(np.mean(x)**2 + np.std(x)**2)
elif statistics == 'cv':
stat_func_ratio = lambda x: np.std(x)/np.mean(x)
stat_func_diff = lambda x: np.std(x) - np.abs(np.mean(x)) # To compute the CV for an already multiplicative variable (GD)
elif statistics == 'iqr':
stat_func = lambda x: np.percentile(x,75) - np.percentile(x,25)
elif statistics == 'percentile':
if perc == None:
print('Do not forget to pass the wanted percentile. I will use 50 by default...')
perc = 50
stat_func = lambda x: np.percentile(x, perc)
else:
print('Wrong statistics asked:', statistics)
sys.exit(1)
return(stat_func)
示例14: arrivals
def arrivals(self, stories, state=6):
''' Chart a plot point for every arrival time in state
'''
arrivals = self.release.kanban().state_arrival_interval(state)
dates = [a['date'] for a in arrivals]
arrivals = [round(a['interval']/60./60., 1) for a in arrivals]
average = numpy.median([arrivals])
std = numpy.std([arrivals])
iql = numpy.percentile([arrivals], 25)
iqh = numpy.percentile([arrivals], 75)
nsul = []
nsuw = []
nsll = []
nslw = []
avg = []
for x in arrivals:
nsul.append(average + (iqh * 3))
nsuw.append(average + (iqh * 2))
nslw.append(average - (iql * 2))
nsll.append(average - (iql * 3))
avg.append(average)
pyplot.plot(dates, arrivals, '*', color='g')
pyplot.plot(dates, nsul, 'o', linestyle='-', color='r')
pyplot.plot(dates, nsuw, '.', linestyle=':', color='y')
pyplot.plot(dates, nslw, '.', linestyle=':', color='y')
pyplot.plot(dates, nsll, 'o', linestyle='-', color='r')
pyplot.plot(dates, avg, '',linestyle='-.', markerfacecolor='None')
pyplot.show(block=False)
示例15: handle_data
def handle_data(self):
current_time = self.current_datetime
try:
location = self.date_index.get_loc(current_time)
except KeyError:
return
if location >= 99:
histories = self.signals.factor[location-99:location]
current_level = histories[-1]
upper = np.percentile(histories, 95)
lower = np.percentile(histories, 5)
mid_upper = np.percentile(histories, 75)
mid_lower = np.percentile(histories, 25)
if current_level > upper:
self.order_to('ru.xsge', 1, 1)
elif current_level < lower:
self.order_to('ru.xsge', -1, 1)
#elif mid_lower < current_level < mid_upper:
# self.order_to('ru.cffex', 1, 0)
self.keep('factor', current_level)
self.keep('factor (95%)', upper)
self.keep('factor (5%)', lower)
self.keep('factor (75%)', mid_upper)
self.keep('factor (25%)', mid_lower)
self.keep('ru.xsge', self.close['ru.xsge'])
else:
return