本文整理汇总了Python中pylab.amax函数的典型用法代码示例。如果您正苦于以下问题:Python amax函数的具体用法?Python amax怎么用?Python amax使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了amax函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classifier_normalize
def classifier_normalize(image,size=32):
"""Normalize characters for classification."""
if amax(image)<1e-3: return zeros((size,size))
cimage = array(image*1.0/amax(image),'f')
cimage = isotropic_rescale(cimage,size)
cimage = csnormalize(cimage)
return cimage
示例2: test1
def test1():
vector_full = NP.array([1.0, 2.5, 2.8, 4.1, 5.1, 5.9, 6.9, 8.1])
vector = vector_full[:-2]
t = NP.arange(vector.shape[0])
showArray('t', t)
showArray('vector', vector)
mask = [True] * vector.shape[0]
mask[2] = False
print 'mask', len(mask), mask
masked_vector = applyMask1D(vector, mask)
masked_t = applyMask1D(vector, mask)
trend = getTrend(t, vector)
print trend
for i in range(masked_t.shape[0]):
v_pred = trend[0] + masked_t[i] * trend[1]
print i, masked_vector[i], v_pred, v_pred - masked_vector[i]
predicted = NP.array([trend[0] + i * trend[1] for i in range(masked_vector.shape[0])])
corrected = NP.array([masked_vector[i] - predicted[i] for i in range(masked_vector.shape[0])])
masked_s = NP.transpose(NP.vstack([masked_vector, predicted, corrected]))
showArray('masked_t', masked_t)
showArray('masked_s', masked_s)
# the main axes is subplot(111) by default
PL.plot(masked_t, masked_s)
s_range = PL.amax(masked_s) - PL.amin(masked_s)
axis([PL.amin(masked_t), PL.amax(masked_t), PL.amin(masked_s) - s_range*0.1, PL.amax(masked_s) + s_range*0.1 ])
xlabel('time (days)')
ylabel('downloads')
title('Dowloads over time')
show()
示例3: csnormalize
def csnormalize(image,f=0.75):
"""Center and size-normalize an image."""
bimage = 1*(image>mean([amax(image),amin(image)]))
w,h = bimage.shape
[xs,ys] = mgrid[0:w,0:h]
s = sum(bimage)
if s<1e-4: return image
s = 1.0/s
cx = sum(xs*bimage)*s
cy = sum(ys*bimage)*s
sxx = sum((xs-cx)**2*bimage)*s
sxy = sum((xs-cx)*(ys-cy)*bimage)*s
syy = sum((ys-cy)**2*bimage)*s
w,v = eigh(array([[sxx,sxy],[sxy,syy]]))
l = sqrt(amax(w))
if l>0.01:
scale = f*max(image.shape)/(4.0*l)
else:
scale = 1.0
m = array([[1.0/scale,0],[0.0,1.0/scale]])
w,h = image.shape
c = array([cx,cy])
d = c-dot(m,array([w/2,h/2]))
image = interpolation.affine_transform(image,m,offset=d,order=1)
return image
示例4: fwhm_2gauss
def fwhm_2gauss(x, y, dx=0.001):
'''
Finds the FWHM for the profile y(x), with accuracy dx=0.001
Uses a 2-Gauss 1D fit.
'''
popt, pcov = curve_fit(gauss2, x, y);
xx = pl.arange(pl.amin(x), pl.amax(x)+dx, dx);
ym = gauss2(xx, popt[0], popt[1], popt[2], popt[3], popt[4], popt[5])
hm = pl.amax(ym/2.0);
y_diff = pl.absolute(ym-hm);
y_diff_sorted = pl.sort(y_diff);
i1 = pl.where(y_diff==y_diff_sorted[0]);
i2 = pl.where(y_diff==y_diff_sorted[1]);
fwhm = pl.absolute(xx[i1]-xx[i2]);
return hm, fwhm, xx, ym
示例5: plot_tuneshifts_2
def plot_tuneshifts_2(ax, spectrum, scan_values, Qs=1, fitrange=None, fittype=None):
(spectral_lines, spectral_intensity) = spectrum
# Normalize power.
normalized_intensity = spectral_intensity / plt.amax(spectral_intensity)
# Prepare plot environment.
palette = _create_cropped_cmap()
x_grid = plt.ones(spectral_lines.shape) * plt.array(scan_values, dtype='float64')
for file_i in xrange(len(scan_values)):
x, y, z = x_grid[:,file_i], spectral_lines[:,file_i], normalized_intensity[:,file_i]
tuneshift_plot = ax[0].scatter(x, y, s=192*plt.log(1+z), c=z, cmap=palette, edgecolors='None')
# Colorbar
cb = plt.colorbar(tuneshift_plot, ax[1], orientation='vertical')
cb.set_label('Power [normalised]')
if fitrange:
if not fittype or fittype=='full':
x, y, z, p = fit_modes_full(spectral_lines, spectral_intensity, scan_values, fitrange)
elif fittype=="0":
x, y, z, p = fit_modes_0(spectral_lines, spectral_intensity, scan_values, fitrange)
else:
raise ValueError("Wrong argument "+fittype+"! Use \"0\" or \"full\"")
ax[0].plot(x, y, 'o', ms=8, mfc='none', mew=2, mec='limegreen')
ax[0].plot(scan_values, z, '-', lw=2, color='limegreen')
ax[0].text(0.95, 0.95, '$\Delta Q \sim $ {:1.2e}'.format(p[0]*1e11*Qs[0]), fontsize=36, color='w', horizontalalignment='right', verticalalignment='top', transform=ax[0].transAxes)
示例6: addDataVectorAccessor
def addDataVectorAccessor(self, data_vector_accessor):
self.__data_vectors_accessors__.append(data_vector_accessor)
_sum = pl.sum(data_vector_accessor.signal)
_min = pl.amin(data_vector_accessor.signal)
_max = pl.amax(data_vector_accessor.signal)
if self.__minimal_signal__ == None:
self.__minimal_signal__ = _sum
self.__minimal_data_vector_accessor__ = data_vector_accessor
self.__min_signal__ = _min
self.__max_signal__ = _max
if _sum < self.__minimal_signal__:
self.__minimal_data_vector_accessor__ = data_vector_accessor
self.__minimal_signal__ = _sum
if _min < self.__min_signal__:
self.__min_signal__ = _min
if _max > self.__max_signal__:
self.__max_signal__ = _max
#collects unique annotations (>0) as a set
if not data_vector_accessor.annotation == None:
unique_annotations = pl.unique(data_vector_accessor.annotation[
pl.where(data_vector_accessor.annotation > 0)])
if len(unique_annotations) > 0:
#union of sets
self.__unique_annotations__ |= set(unique_annotations)
示例7: __init__
def __init__(self, X, c):
self.n, self.N = X.shape
self.X = X
self.c = c
# Calculate max value of the 2d array
self.max = amax(X)
示例8: average_size
def average_size(img, minimum_area=10, maximum_area=40):
"计算页面中整个连接体的 平均的大小,可能是因为manga中的字体都差不多大"
components = get_connected_components(img)
sorted_components = sorted(components,key=area_bb)
#sorted_components = sorted(components,key=lambda x:area_nz(x,binary))
areas = zeros(img.shape)
for component in sorted_components:
#As the input components are sorted, we don't overwrite
#a given area again (it will already have our max value)
if amax(areas[component])>0: continue
#take the sqrt of the area of the bounding box
areas[component] = area_bb(component)**0.5
#alternate implementation where we just use area of black pixels in cc
#areas[component]=area_nz(component,binary)
#we lastly take the median (middle value of sorted array) within the region of interest
#region of interest is defaulted to those ccs between 3 and 100 pixels on a side (text sized)
aoi = areas[(areas>minimum_area)&(areas<maximum_area)]
if len(aoi)==0:
return 0
print 'np.median(aoi) = ',np.median(aoi)
return np.median(aoi)
示例9: _calculate_spectra_sussix
def _calculate_spectra_sussix(sx, sy, Q_x, Q_y, Q_s, n_lines):
n_turns, n_files = sx.shape
# Allocate memory for output.
oxx, axx = plt.zeros((n_lines, n_files)), plt.zeros((n_lines, n_files))
oyy, ayy = plt.zeros((n_lines, n_files)), plt.zeros((n_lines, n_files))
# Initialise Sussix object.
SX = PySussix.Sussix()
x, xp, y, yp = sx.real, sx.imag, sy.real, sy.imag
for file_i in xrange(n_files):
SX.sussix_inp(nt1=1, nt2=n_turns, idam=2, ir=0, tunex=Q_x[file_i] % 1, tuney=Q_y[file_i] % 1)
SX.sussix(x[:,file_i], xp[:,file_i], y[:,file_i], yp[:,file_i], sx[:,file_i], sx[:,file_i])
# Amplitude normalisation
SX.ax /= plt.amax(SX.ax)
SX.ay /= plt.amax(SX.ay)
# Tunes
SX.ox = plt.absolute(SX.ox)
SX.oy = plt.absolute(SX.oy)
if file_i==0:
tunexsx = SX.ox[plt.argmax(SX.ax)]
tuneysx = SX.oy[plt.argmax(SX.ay)]
print "\n*** Tunes from Sussix"
print " tunex", tunexsx, ", tuney", tuneysx, "\n"
# Tune normalisation
SX.ox = (SX.ox - (Q_x[file_i] % 1)) / Q_s[file_i]
SX.oy = (SX.oy - (Q_y[file_i] % 1)) / Q_s[file_i]
# Sort
CX = plt.rec.fromarrays([SX.ox, SX.ax], names='ox, ax')
CX.sort(order='ax')
CY = plt.rec.fromarrays([SX.oy, SX.ay], names='oy, ay')
CY.sort(order='ay')
ox, ax, oy, ay = CX.ox, CX.ax, CY.oy, CY.ay
oxx[:,file_i], axx[:,file_i], oyy[:,file_i], ayy[:,file_i] = ox, ax, oy, ay
spectra = {}
spectra['horizontal'] = (oxx, axx)
spectra['vertical'] = (oyy, ayy)
return spectra
示例10: fwhm
def fwhm(x, y):
hm = pl.amax(y/2.0);
y_diff = pl.absolute(y-hm);
y_diff_sorted = pl.sort(y_diff);
i1 = pl.where(y_diff==y_diff_sorted[0]);
i2 = pl.where(y_diff==y_diff_sorted[1]);
fwhm = pl.absolute(x[i1]-x[i2]);
return hm, fwhm
示例11: remove_noise
def remove_noise(line,minsize=8):
"""Remove small pixels from an image."""
if minsize==0: return line
bin = (line>0.5*amax(line))
labels,n = morph.label(bin)
sums = measurements.sum(bin,labels,range(n+1))
sums = sums[labels]
good = minimum(bin,1-(sums>0)*(sums<minsize))
return good
示例12: findHighOD
def findHighOD(data):
'''Find the highest OD value to set for plots'''
hi = 0
for c, wDict in data.items():
for w, curve in wDict.items():
max = py.amax(curve)
if max > hi:
hi = max
return hi
示例13: translate_back
def translate_back(outputs,threshold=0.7,pos=0):
"""Translate back. Thresholds on class 0, then assigns
the maximum class to each region."""
# print outputs
labels,n = measurements.label(outputs[:,0]<threshold)
mask = tile(labels.reshape(-1,1), (1,outputs.shape[1]))
maxima = measurements.maximum_position(outputs,mask,arange(1,amax(mask)+1))
if pos: return maxima
return [c for (r,c) in maxima]
示例14: QuickHull
def QuickHull(points):
"""Randomized divide and conquer convex hull.
Args:
points: NxD matrix of points in dimension D.
"""
N, D = points.shape
dim = random.randint(0, D-1)
min_dim = p.amin(points.T, dim)
max_dim = p.amax(points.T, dim)
示例15: plot_risetimes
def plot_risetimes(a, b, **kwargs):
# plt.ion()
# if kwargs is not None:
# for key, value in kwargs.iteritems():
# if key == 'file_list':
# file_list = value
# if key == 'scan_line':
# scan_line = value
# varray = plt.array(get_value_from_cfg(file_list, scan_line))
n_files = a.shape[-1]
cmap = plt.get_cmap('jet')
c = [cmap(i) for i in plt.linspace(0, 1, n_files)]
fig1, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))
[ax.set_color_cycle(c) for ax in (ax1, ax2)]
r = []
for i in xrange(n_files):
x, y = a[:,i], b[:,i]
# xo, yo = x, y #, get_envelope(x, y)
xo, yo = get_envelope(x, y)
p = plt.polyfit(xo, np.log(yo), 1)
# Right way to fit... a la Nicolas - the fit expert!
l = ax1.plot(x, plt.log(plt.absolute(y)))
lcolor = l[-1].get_color()
ax1.plot(xo, plt.log(yo), color=lcolor, marker='o', mec=None)
ax1.plot(x, p[1] + x * p[0], color=lcolor, ls='--', lw=3)
l = ax2.plot(x, y)
lcolor = l[-1].get_color()
ax2.plot(xo, yo, 'o', color=lcolor)
xi = plt.linspace(plt.amin(x), plt.amax(x))
yi = plt.exp(p[1] + p[0] * xi)
ax2.plot(xi, yi, color=lcolor, ls='--', lw=3)
print p[1], p[0], 1 / p[0]
# plt.draw()
# ax1.cla()
# ax2.cla()
r.append(1/p[0])
ax2.set_ylim(0, 1000)
plt.figure(2)
plt.plot(r, lw=3, c='purple')
# plt.gca().set_ylim(0, 10000)
# ax3 = plt.subplot(111)
# ax3.semilogy(x, y)
# ax3.semilogy(xo, yo)
return r