本文整理汇总了Python中autograd.numpy.min方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.min方法的具体用法?Python numpy.min怎么用?Python numpy.min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autograd.numpy
的用法示例。
在下文中一共展示了numpy.min方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_thickness_at_chord_fraction_legacy
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def get_thickness_at_chord_fraction_legacy(self, chord_fraction):
# Returns the (interpolated) camber at a given location(s). The location is specified by the chord fraction, as measured from the leading edge. Thickness is nondimensionalized by chord (i.e. this function returns t/c at a given x/c).
chord = np.max(self.coordinates[:, 0]) - np.min(
self.coordinates[:, 0]) # This should always be 1, but this is just coded for robustness.
x = chord_fraction * chord + min(self.coordinates[:, 0])
upperCoors = self.upper_coordinates()
lowerCoors = self.lower_coordinates()
y_upper_func = sp_interp.interp1d(x=upperCoors[:, 0], y=upperCoors[:, 1], copy=False, fill_value='extrapolate')
y_lower_func = sp_interp.interp1d(x=lowerCoors[:, 0], y=lowerCoors[:, 1], copy=False, fill_value='extrapolate')
y_upper = y_upper_func(x)
y_lower = y_lower_func(x)
thickness = np.maximum(y_upper - y_lower, 0)
return thickness
示例2: get_camber_at_chord_fraction_legacy
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def get_camber_at_chord_fraction_legacy(self, chord_fraction):
# Returns the (interpolated) camber at a given location(s). The location is specified by the chord fraction, as measured from the leading edge. Camber is nondimensionalized by chord (i.e. this function returns camber/c at a given x/c).
chord = np.max(self.coordinates[:, 0]) - np.min(
self.coordinates[:, 0]) # This should always be 1, but this is just coded for robustness.
x = chord_fraction * chord + min(self.coordinates[:, 0])
upperCoors = self.upper_coordinates()
lowerCoors = self.lower_coordinates()
y_upper_func = sp_interp.interp1d(x=upperCoors[:, 0], y=upperCoors[:, 1], copy=False, fill_value='extrapolate')
y_lower_func = sp_interp.interp1d(x=lowerCoors[:, 0], y=lowerCoors[:, 1], copy=False, fill_value='extrapolate')
y_upper = y_upper_func(x)
y_lower = y_lower_func(x)
camber = (y_upper + y_lower) / 2
return camber
示例3: plot_images
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def plot_images(images, ax, ims_per_row=5, padding=5, digit_dimensions=(28, 28),
cmap=matplotlib.cm.binary, vmin=None, vmax=None):
"""Images should be a (N_images x pixels) matrix."""
N_images = images.shape[0]
N_rows = (N_images - 1) // ims_per_row + 1
pad_value = np.min(images.ravel())
concat_images = np.full(((digit_dimensions[0] + padding) * N_rows + padding,
(digit_dimensions[1] + padding) * ims_per_row + padding), pad_value)
for i in range(N_images):
cur_image = np.reshape(images[i, :], digit_dimensions)
row_ix = i // ims_per_row
col_ix = i % ims_per_row
row_start = padding + (padding + digit_dimensions[0]) * row_ix
col_start = padding + (padding + digit_dimensions[1]) * col_ix
concat_images[row_start: row_start + digit_dimensions[0],
col_start: col_start + digit_dimensions[1]] = cur_image
cax = ax.matshow(concat_images, cmap=cmap, vmin=vmin, vmax=vmax)
plt.xticks(np.array([]))
plt.yticks(np.array([]))
return cax
示例4: bound_by_data
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def bound_by_data(Z, Data):
"""
Determine lower and upper bound for each dimension from the Data, and project
Z so that all points in Z live in the bounds.
Z: m x d
Data: n x d
Return a projected Z of size m x d.
"""
n, d = Z.shape
Low = np.min(Data, 0)
Up = np.max(Data, 0)
LowMat = np.repeat(Low[np.newaxis, :], n, axis=0)
UpMat = np.repeat(Up[np.newaxis, :], n, axis=0)
Z = np.maximum(LowMat, Z)
Z = np.minimum(UpMat, Z)
return Z
示例5: get_starlet_shape
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def get_starlet_shape(shape, lvl = None):
""" Get the pad shape for a starlet transform
"""
#Number of levels for the Starlet decomposition
lvl_max = np.int(np.log2(np.min(shape[-2:])))
if (lvl is None) or lvl > lvl_max:
lvl = lvl_max
return lvl
示例6: my_t_test
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def my_t_test(labels, theoretical, observed, min_samples=25):
assert theoretical.ndim == 1 and observed.ndim == 2
assert len(theoretical) == observed.shape[
0] and len(theoretical) == len(labels)
n_observed = np.sum(observed > 0, axis=1)
theoretical, observed = theoretical[
n_observed > min_samples], observed[n_observed > min_samples, :]
labels = np.array(list(map(str, labels)))[n_observed > min_samples]
n_observed = n_observed[n_observed > min_samples]
runs = observed.shape[1]
observed_mean = np.mean(observed, axis=1)
bias = observed_mean - theoretical
variances = np.var(observed, axis=1)
t_vals = bias / np.sqrt(variances) * np.sqrt(runs)
# get the p-values
abs_t_vals = np.abs(t_vals)
p_vals = 2.0 * scipy.stats.t.sf(abs_t_vals, df=runs - 1)
print("# labels, p-values, empirical-mean, theoretical-mean, nonzero-counts")
toPrint = np.array([labels, p_vals, observed_mean,
theoretical, n_observed]).transpose()
toPrint = toPrint[np.array(toPrint[:, 1], dtype='float').argsort()[
::-1]] # reverse-sort by p-vals
print(toPrint)
print("Note p-values are for t-distribution, which may not be a good approximation to the true distribution")
# p-values should be uniformly distributed
# so then the min p-value should be beta distributed
return scipy.stats.beta.cdf(np.min(p_vals), 1, len(p_vals))
示例7: get_sharp_TE_airfoil
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def get_sharp_TE_airfoil(self):
# Returns a version of the airfoil with a sharp trailing edge.
upper_original_coors = self.upper_coordinates() # Note: includes leading edge point, be careful about duplicates
lower_original_coors = self.lower_coordinates() # Note: includes leading edge point, be careful about duplicates
# Find data about the TE
# Get the scale factor
x_mcl = self.mcl_coordinates[:, 0]
x_max = np.max(x_mcl)
x_min = np.min(x_mcl)
scale_factor = (x_mcl - x_min) / (x_max - x_min) # linear contraction
# Do the contraction
upper_minus_mcl_adjusted = self.upper_minus_mcl - self.upper_minus_mcl[-1, :] * np.expand_dims(scale_factor, 1)
# Recreate coordinates
upper_coordinates_adjusted = np.flipud(self.mcl_coordinates + upper_minus_mcl_adjusted)
lower_coordinates_adjusted = self.mcl_coordinates - upper_minus_mcl_adjusted
coordinates = np.vstack((
upper_coordinates_adjusted[:-1, :],
lower_coordinates_adjusted
))
# Make a new airfoil with the coordinates
name = self.name + ", with sharp TE"
new_airfoil = Airfoil(name=name, coordinates=coordinates, repanel=False)
return new_airfoil
示例8: cosspace
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def cosspace(min=0, max=1, n_points=50):
mean = (max + min) / 2
amp = (max - min) / 2
return mean + amp * np.cos(np.linspace(np.pi, 0, n_points))
示例9: test_min
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def test_min(): stat_check(np.min)
示例10: test_min
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def test_min():
def fun(x): return np.min(x)
mat = npr.randn(10, 11)
check_grads(fun)(mat)
示例11: test_min_axis
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def test_min_axis():
def fun(x): return np.min(x, axis=1)
mat = npr.randn(3, 4, 5)
check_grads(fun)(mat)
示例12: test_min_axis_keepdims
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def test_min_axis_keepdims():
def fun(x): return np.min(x, axis=1, keepdims=True)
mat = npr.randn(3, 4, 5)
check_grads(fun)(mat)
示例13: constrain
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def constrain(val, min_val, max_val):
return min(max_val, max(min_val, val))
示例14: meddistance
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def meddistance(X, subsample=None, mean_on_fail=True):
"""
Compute the median of pairwise distances (not distance squared) of points
in the matrix. Useful as a heuristic for setting Gaussian kernel's width.
Parameters
----------
X : n x d numpy array
mean_on_fail: True/False. If True, use the mean when the median distance is 0.
This can happen especially, when the data are discrete e.g., 0/1, and
there are more slightly more 0 than 1. In this case, the m
Return
------
median distance
"""
if subsample is None:
D = dist_matrix(X, X)
Itri = np.tril_indices(D.shape[0], -1)
Tri = D[Itri]
med = np.median(Tri)
if med <= 0:
# use the mean
return np.mean(Tri)
return med
else:
assert subsample > 0
rand_state = np.random.get_state()
np.random.seed(9827)
n = X.shape[0]
ind = np.random.choice(n, min(subsample, n), replace=False)
np.random.set_state(rand_state)
# recursion just one
return meddistance(X[ind, :], None, mean_on_fail)
示例15: plot_runtime
# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import min [as 别名]
def plot_runtime(ex, fname, func_xvalues, xlabel, func_title=None):
results = glo.ex_load_result(ex, fname)
value_accessor = lambda job_results: job_results['time_secs']
vf_pval = np.vectorize(value_accessor)
# results['job_results'] is a dictionary:
# {'test_result': (dict from running perform_test(te) '...':..., }
times = vf_pval(results['job_results'])
repeats, _, n_methods = results['job_results'].shape
time_avg = np.mean(times, axis=0)
time_std = np.std(times, axis=0)
xvalues = func_xvalues(results)
#ns = np.array(results[xkey])
#te_proportion = 1.0 - results['tr_proportion']
#test_sizes = ns*te_proportion
line_styles = func_plot_fmt_map()
method_labels = get_func2label_map()
func_names = [f.__name__ for f in results['method_job_funcs'] ]
for i in range(n_methods):
te_proportion = 1.0 - results['tr_proportion']
fmt = line_styles[func_names[i]]
#plt.errorbar(ns*te_proportion, mean_rejs[:, i], std_pvals[:, i])
method_label = method_labels[func_names[i]]
plt.errorbar(xvalues, time_avg[:, i], yerr=time_std[:,i], fmt=fmt,
label=method_label)
ylabel = 'Time (s)'
plt.ylabel(ylabel)
plt.xlabel(xlabel)
plt.xlim([np.min(xvalues), np.max(xvalues)])
plt.xticks( xvalues, xvalues )
plt.legend(loc='best')
plt.gca().set_yscale('log')
title = '%s. %d trials. '%( results['prob_label'],
repeats ) if func_title is None else func_title(results)
plt.title(title)
#plt.grid()
return results