本文整理汇总了Python中scipy.amax函数的典型用法代码示例。如果您正苦于以下问题:Python amax函数的具体用法?Python amax怎么用?Python amax使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了amax函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_drainage_curve
def plot_drainage_curve(self,
data=None,
x_values='capillary_pressure',
y_values='invading_phase_saturation'):
r"""
Plot the drainage curve as the non-wetting phase saturation vs the
applied capillary pressure.
Parameters
----------
data : dictionary of arrays
This dictionary should be obtained from the ``get_drainage_data``
method.
x_values and y_values : string
The dictionary keys of the arrays containing the x-values and
y-values
"""
# Begin creating nicely formatted plot
if data is None:
data = self.get_drainage_data()
xdata = data[x_values]
ydata = data[y_values]
fig = plt.figure()
plt.plot(xdata, ydata, 'ko-')
plt.ylabel(y_values)
plt.xlabel(x_values)
plt.grid(True)
if sp.amax(xdata) <= 1:
plt.xlim(xmin=0, xmax=1)
if sp.amax(ydata) <= 1:
plt.ylim(ymin=0, ymax=1)
return fig
示例2: test_distance_center
def test_distance_center():
shape = sp.array([7, 5, 9])
spacing = sp.array([2, 1, 0.5])
pn = OpenPNM.Network.Cubic(shape=shape, spacing=spacing)
sx, sy, sz = spacing
center_coord = sp.around(topology.find_centroid(pn['pore.coords']), 7)
cx, cy, cz = center_coord
coords = pn['pore.coords']
x, y, z = coords.T
coords = sp.concatenate((coords, center_coord.reshape((1, 3))))
pn['pore.center'] = False
mask1 = (x <= (cx + sx/2)) * (y <= (cy + sy/2)) * (z <= (cz + sz/2))
mask2 = (x >= (cx - sx/2)) * (y >= (cy - sy/2)) * (z >= (cz - sz/2))
center_pores_mask = pn.Ps[mask1 * mask2]
pn['pore.center'][center_pores_mask] = True
center = pn.Ps[pn['pore.center']]
L1 = sp.amax(topology.find_pores_distance(network=pn,
pores1=center,
pores2=pn.Ps))
L2 = sp.amax(topology.find_pores_distance(network=pn,
pores1=pn.Ps,
pores2=pn.Ps))
l1 = ((shape[0] - 1) * sx) ** 2
l2 = ((shape[1] - 1) * sy) ** 2
l3 = ((shape[2] - 1) * sz) ** 2
L3 = sp.sqrt(l1 + l2 + l3)
assert sp.around(L1 * 2, 7) == sp.around(L2, 7)
assert sp.around(L2, 7) == sp.around(L3, 7)
示例3: integrate
def integrate(self,t,u,v):
# integrate only one step in time.
# assume same delta in x and y
maxu = amax(u);
maxv = amax(v);
maxVel = amax((maxu,maxv));
dt = self.cflConstant*self.dx/maxVel;
print 'Time step selected: ', dt;
k1 = self.dudt(t,u,v);
l1 = self.dvdt(t,u,v);
k2 = self.dudt(t+dt/2, u+(dt*k1/2), v+(dt*l1/2));
l2 = self.dvdt(t+dt/2, u+(dt*k1/2), v+(dt*l1/2));
k3 = self.dudt(t+dt/2, u+(dt*k2/2), v+(dt*l2/2));
l3 = self.dvdt(t+dt/2, u+(dt*k2/2), v+(dt*l2/2));
k4 = self.dudt(t+dt, u+(dt*k3), v+(dt*l3));
l4 = self.dvdt(t+dt, u+(dt*k3), v+(dt*l3));
k = (k1 + 2*k2 + 2*k3 + k4)/6;
l = (l1 + 2*l2 + 2*l3 + l4)/6;
un = u + dt*k;
vn = v + dt*k;
tn = t + dt;
return (tn,un,vn);
示例4: amalgamate_throat_data
def amalgamate_throat_data(self,fluids='all'):
r"""
Returns a dictionary containing ALL throat data from all fluids, physics and geometry objects
"""
self._throat_data_amalgamate = {}
if type(fluids)!= sp.ndarray and fluids=='all':
fluids = self._fluids
elif type(fluids)!= sp.ndarray:
fluids = sp.array(fluids,ndmin=1)
#Add fluid data
for item in fluids:
if type(item)==sp.str_: item = self.find_object_by_name(item)
for key in item._throat_data.keys():
if sp.amax(item._throat_data[key]) < sp.inf:
dict_name = item.name+'_throat_'+key
self._throat_data_amalgamate.update({dict_name : item._throat_data[key]})
for key in item._throat_info.keys():
if sp.amax(item._throat_info[key]) < sp.inf:
dict_name = item.name+'_throat_label_'+key
self._throat_data_amalgamate.update({dict_name : item._throat_info[key]})
#Add geometry data
for key in self._throat_data.keys():
if sp.amax(self._throat_data[key]) < sp.inf:
dict_name = 'throat'+'_'+key
self._throat_data_amalgamate.update({dict_name : self._throat_data[key]})
for key in self._throat_info.keys():
if sp.amax(self._throat_info[key]) < sp.inf:
dict_name = 'throat'+'_label_'+key
self._throat_data_amalgamate.update({dict_name : self._throat_info[key]})
return self._throat_data_amalgamate
示例5: test_get_coords
def test_get_coords(self):
f = OpenPNM.Network.models.pore_topology.adjust_spacing
self.net.models.add(propname='pore.coords2',
model=f,
new_spacing=2)
assert 'pore.coords2' in self.net.keys()
a = sp.amax(self.net['pore.coords'])
assert sp.amax(self.net['pore.coords2']) == 2*a
示例6: porosity_profile
def porosity_profile(network,
fig=None, axis=2):
r'''
Compute and plot the porosity profile in all three dimensions
Parameters
----------
network : OpenPNM Network object
axis : integer type 0 for x-axis, 1 for y-axis, 2 for z-axis
Notes
-----
the area of the porous medium at any position is calculated from the
maximum pore coordinates in each direction
'''
if fig is None:
fig = _plt.figure()
L_x = _sp.amax(network['pore.coords'][:,0]) + _sp.mean(((21/88.0)*network['pore.volume'])**(1/3.0))
L_y = _sp.amax(network['pore.coords'][:,1]) + _sp.mean(((21/88.0)*network['pore.volume'])**(1/3.0))
L_z = _sp.amax(network['pore.coords'][:,2]) + _sp.mean(((21/88.0)*network['pore.volume'])**(1/3.0))
if axis is 0:
xlab = 'x-direction'
area = L_y*L_z
elif axis is 1:
xlab = 'y-direction'
area = L_x*L_z
else:
axis = 2
xlab = 'z-direction'
area = L_x*L_y
n_max = _sp.amax(network['pore.coords'][:,axis]) + _sp.mean(((21/88.0)*network['pore.volume'])**(1/3.0))
steps = _sp.linspace(0,n_max,100,endpoint=True)
vals = _sp.zeros_like(steps)
p_area = _sp.zeros_like(steps)
t_area = _sp.zeros_like(steps)
rp = ((21/88.0)*network['pore.volume'])**(1/3.0)
p_upper = network['pore.coords'][:,axis] + rp
p_lower = network['pore.coords'][:,axis] - rp
TC1 = network['throat.conns'][:,0]
TC2 = network['throat.conns'][:,1]
t_upper = network['pore.coords'][:,axis][TC1]
t_lower = network['pore.coords'][:,axis][TC2]
for i in range(0,len(steps)):
p_temp = (p_upper > steps[i])*(p_lower < steps[i])
t_temp = (t_upper > steps[i])*(t_lower < steps[i])
p_area[i] = sum((22/7.0)*(rp[p_temp]**2 - (network['pore.coords'][:,axis][p_temp]-steps[i])**2))
t_area[i] = sum(network['throat.area'][t_temp])
vals[i] = (p_area[i]+t_area[i])/area
yaxis = vals
xaxis = steps/n_max
_plt.plot(xaxis,yaxis,'bo-')
_plt.xlabel(xlab)
_plt.ylabel('Porosity')
fig.show()
示例7: standarizeImage
def standarizeImage(im):
im = array(im, 'float32')
if im.shape[0] > 480:
resize_factor = 480.0 / im.shape[0] # don't remove trailing .0 to avoid integer devision
im = imresize(im, resize_factor)
if amax(im) > 1.1:
im = im / 255.0
assert((amax(im) > 0.01) & (amax(im) <= 1))
assert((amin(im) >= 0.00))
return im
示例8: standardizeImage
def standardizeImage(im): #Scales image down to 640x480 or whatever the correct aspect ratio is with conf.imSize as the height
im = array(im, 'float32')
if im.shape[0] > conf.imSize:
resize_factor = float(conf.imSize) / im.shape[0] # don't remove trailing .0 to avoid integer devision
im = imresize(im, resize_factor)
if amax(im) > 1.1:
im = im / 255.0
assert((amax(im) > 0.01) & (amax(im) <= 1))
assert((amin(im) >= 0.00))
return im
示例9: __init__
def __init__(
self, spike_count_range, train_count_range, num_units_range,
firing_rate=50 * pq.Hz):
self.spike_count_range = spike_count_range
self.train_count_range = train_count_range
self.num_units_range = num_units_range
self.num_trains_per_spike_count = \
sp.amax(num_units_range) * sp.amax(train_count_range)
self.trains = [
[stg.gen_homogeneous_poisson(firing_rate, max_spikes=num_spikes)
for i in xrange(self.num_trains_per_spike_count)]
for num_spikes in spike_count_range]
示例10: test_respects_refractory_period
def test_respects_refractory_period(self):
refractory = 100 * pq.ms
st = self.invoke_gen_func(
self.highRate, max_spikes=1000, refractory=refractory)
self.assertGreater(
sp.amax(sp.absolute(sp.diff(st.rescale(pq.s).magnitude))),
refractory.rescale(pq.s).magnitude)
st = self.invoke_gen_func(
self.highRate, t_stop=10 * pq.s, refractory=refractory)
self.assertGreater(
sp.amax(sp.absolute(sp.diff(st.rescale(pq.s).magnitude))),
refractory.rescale(pq.s).magnitude)
示例11: test_neighbor_min
def test_neighbor_min(self):
catch = self.geo.pop('pore.seed', None)
catch = self.geo.models.pop('pore.seed', None)
catch = self.geo.models.pop('throat.seed', None)
mod = gm.pore_misc.neighbor
self.geo['throat.seed'] = sp.rand(self.net.Nt,)
self.geo.models.add(model=mod,
propname='pore.seed',
throat_prop='throat.seed',
mode='min')
assert sp.all(sp.in1d(self.geo['pore.seed'], self.geo['throat.seed']))
pmax = sp.amax(self.geo['pore.seed'])
tmax = sp.amax(self.geo['throat.seed'])
assert pmax <= tmax
示例12: expectation_prop_inner
def expectation_prop_inner(m0,V0,Y,Z,F,z,needed):
#expectation propagation on multivariate gaussian for soft inequality constraint
#m0,v0 are mean vector , covariance before EP
#Y is inequality value, Z is sign, 1 for geq, -1 for leq, F is softness variance
#z is number of ep rounds to run
#returns mt, Vt the value and variance for observations created by ep
m0=sp.array(m0).flatten()
V0=sp.array(V0)
n = V0.shape[0]
print "expectation prpagation running on "+str(n)+" dimensions for "+str(z)+" loops:"
mt =sp.zeros(n)
Vt= sp.eye(n)*float(1e10)
m = sp.empty(n)
V = sp.empty([n,n])
conv = sp.empty(z)
for i in xrange(z):
#compute the m V give ep obs
m,V = gaussian_fusion(m0,mt,V0,Vt)
mtprev=mt.copy()
Vtprev=Vt.copy()
for j in [k for k in xrange(n) if needed[k]]:
print [i,j]
#the cavity dist at index j
tmp = 1./(Vt[j,j]-V[j,j])
v_ = (V[j,j]*Vt[j,j])*tmp
m_ = tmp*(m[j]*Vt[j, j]-mt[j]*V[j, j])
alpha = sp.sign(Z[j])*(m_-Y[j]) / (sp.sqrt(v_+F[j]))
pr = PhiR(alpha)
if sp.isnan(pr):
pr = -alpha
beta = pr*(pr+alpha)/(v_+F[j])
kappa = sp.sign(Z[j])*(pr+alpha) / (sp.sqrt(v_+F[j]))
#print [alpha,beta,kappa,pr]
mt[j] = m_+1./kappa
#mt[j] = min(abs(mt[j]),1e5)*sp.sign(mt[j])
Vt[j,j] = min(1e10,1./beta - v_)
#print sp.amax(mtprev-mt)
#print sp.amax(sp.diagonal(Vtprev)-sp.diagonal(Vt))
#TODO make this a ratio instead of absolute
delta = max(sp.amax(mtprev-mt),sp.amax(sp.diagonal(Vtprev)-sp.diagonal(Vt)))
conv[i]=delta
print "EP finished with final max deltas "+str(conv[-3:])
V = V0.dot(spl.solve(V0+Vt,Vt))
m = V.dot((spl.solve(V0,m0)+spl.solve(Vt,mt)).T)
return mt, Vt
示例13: standardizeImage
def standardizeImage(im): #Scales image down to 640x480
im = array(im, 'float32')
if im.shape[0] > conf.imSize:
resize_factor = float(conf.imSize) / im.shape[0] # don't remove trailing .0 to avoid integer devision
im = imresize(im, resize_factor)
if amax(im) > 1.1:
im = im / 255.0
assert((amax(im) > 0.01) & (amax(im) <= 1))
assert((amin(im) >= 0.00))
"""r = 480.0 / im.shape[1]
dim = (480, int(im.shape[0] * r))
im = cv2.resize(im, dim, interpolation = cv2.INTER_AREA)"""
return im
示例14: output_percentile_set
def output_percentile_set(data_field, args):
r"""
Does three sets of percentiles and stacks them as columns: raw data,
absolute value data, normalized+absolute value
"""
data = {}
#
# outputting percentiles of initial subtraction to screen
field = data_field.clone()
pctle = Percentiles(field, percentiles=args.perc)
pctle.process()
data['raw'] = pctle.processed_data
#
# normalizing data
field = data_field.clone()
field.data_map = field.data_map/sp.amax(sp.absolute(field.data_map))
field.data_vector = sp.ravel(field.data_map)
pctle = Percentiles(field, percentiles=args.perc)
pctle.process()
data['norm'] = pctle.processed_data
#
# taking absolute value of data
field = data_field.clone()
field.data_map = sp.absolute(field.data_map)
field.data_vector = sp.absolute(field.data_vector)
pctle = Percentiles(field, percentiles=args.perc)
pctle.process()
data['abs'] = pctle.processed_data
#
# absolute value + normed
field.data_map = field.data_map/sp.amax(field.data_map)
field.data_vector = sp.ravel(field.data_map)
pctle = Percentiles(field, percentiles=args.perc)
pctle.process()
data['abs+norm'] = pctle.processed_data
#
# outputting stacked percentiles
fmt = ' {:>6.2f}\t{: 0.6e}\t{: 0.6e}\t{: 0.6e}\t{: 0.6e}\n'
content = 'Percentile\tRaw Data\tAbsolute\tNormalized\tNorm+abs\n'
data = zip(args.perc, data['raw'].values(),
data['abs'].values(),
data['norm'].values(),
data['abs+norm'].values())
#
for row in data:
content += fmt.format(*row)
content += '\n'
print(content)
示例15: plot_delta
def plot_delta():
beta = 0.99
N = 1000
u = lambda c: sp.sqrt(c)
W = sp.linspace(0,1,N)
X, Y = sp.meshgrid(W,W)
Wdiff = sp.transpose(X-Y)
index = Wdiff <0
Wdiff[index] = 0
util_grid = u(Wdiff)
util_grid[index] = -10**10
Vprime = sp.zeros((N,1))
delta = sp.ones(1)
tol = 10**-9
it = 0
max_iter = 500
while (delta[-1] >= tol) and (it < max_iter):
V = Vprime
it += 1;
print(it)
val = util_grid + beta*sp.transpose(V)
Vprime = sp.amax(val, axis = 1)
Vprime = Vprime.reshape((N,1))
delta = sp.append(delta,sp.dot(sp.transpose(Vprime - V),Vprime-V))
plt.figure()
plt.plot(delta[1:])
plt.ylabel(r'$\delta_k$')
plt.xlabel('iteration')
plt.savefig('convergence.pdf')