本文整理匯總了Python中numpy.amin方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.amin方法的具體用法?Python numpy.amin怎麽用?Python numpy.amin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.amin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _check_satisfy_constraints
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def _check_satisfy_constraints(self, label, xmin, ymin, xmax, ymax, width, height):
"""Check if constrains are satisfied"""
if (xmax - xmin) * (ymax - ymin) < 2:
return False # only 1 pixel
x1 = float(xmin) / width
y1 = float(ymin) / height
x2 = float(xmax) / width
y2 = float(ymax) / height
object_areas = self._calculate_areas(label[:, 1:])
valid_objects = np.where(object_areas * width * height > 2)[0]
if valid_objects.size < 1:
return False
intersects = self._intersect(label[valid_objects, 1:], x1, y1, x2, y2)
coverages = self._calculate_areas(intersects) / object_areas[valid_objects]
coverages = coverages[np.where(coverages > 0)[0]]
return coverages.size > 0 and np.amin(coverages) > self.min_object_covered
示例2: draw_outputs
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def draw_outputs(img, outputs, class_names=None):
boxes, objectness, classes = outputs
#boxes, objectness, classes = boxes[0], objectness[0], classes[0]
wh = np.flip(img.shape[0:2])
if img.ndim == 2 or img.shape[2] == 1:
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
min_wh = np.amin(wh)
if min_wh <= 100:
font_size = 0.5
else:
font_size = 1
for i in range(classes.shape[0]):
x1y1 = tuple((np.array(boxes[i][0:2]) * wh).astype(np.int32))
x2y2 = tuple((np.array(boxes[i][2:4]) * wh).astype(np.int32))
img = cv2.rectangle(img, x1y1, x2y2, (255, 0, 0), 1)
img = cv2.putText(img, '{}'.format(int(classes[i])), x1y1, cv2.FONT_HERSHEY_COMPLEX_SMALL, font_size,
(0, 0, 255), 1)
return img
示例3: draw_labels
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def draw_labels(x, y, class_names=None):
img = x.numpy()
if img.ndim == 2 or img.shape[2] == 1:
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
boxes, classes = tf.split(y, (4, 1), axis=-1)
classes = classes[..., 0]
wh = np.flip(img.shape[0:2])
min_wh = np.amin(wh)
if min_wh <= 100:
font_size = 0.5
else:
font_size = 1
for i in range(len(boxes)):
x1y1 = tuple((np.array(boxes[i][0:2]) * wh).astype(np.int32))
x2y2 = tuple((np.array(boxes[i][2:4]) * wh).astype(np.int32))
img = cv2.rectangle(img, x1y1, x2y2, (255, 0, 0), 1)
if class_names:
img = cv2.putText(img, class_names[classes[i]], x1y1, cv2.FONT_HERSHEY_COMPLEX_SMALL, font_size,
(0, 0, 255), 1)
else:
img = cv2.putText(img, str(classes[i]), x1y1, cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)
return img
示例4: get_wmin_wmax_tmax_ia_def
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def get_wmin_wmax_tmax_ia_def(self, tol):
from numpy import log, exp, sqrt, where, amin, amax
"""
This is a default choice of the wmin and wmax parameters for a log grid along
imaginary axis. The default choice is based on the eigenvalues.
"""
E = self.ksn2e[0,0,:]
E_fermi = self.fermi_energy
E_homo = amax(E[where(E<=E_fermi)])
E_gap = amin(E[where(E>E_fermi)]) - E_homo
E_maxdiff = amax(E) - amin(E)
d = amin(abs(E_homo-E)[where(abs(E_homo-E)>1e-4)])
wmin_def = sqrt(tol * (d**3) * (E_gap**3)/(d**2+E_gap**2))
wmax_def = (E_maxdiff**2/tol)**(0.250)
tmax_def = -log(tol)/ (E_gap)
tmin_def = -100*log(1.0-tol)/E_maxdiff
return wmin_def, wmax_def, tmin_def,tmax_def
示例5: assign_mesh
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def assign_mesh(self, mesh):
interface = self.interface
box = interface.universe.dimensions[:3]
interface.target_mesh = mesh
if not isinstance(interface.target_mesh, (int, float)):
raise TypeError(messages.MESH_NAN)
if interface.target_mesh <= 0:
raise ValueError(messages.MESH_NEGATIVE)
if interface.target_mesh >= np.amin(box) / 2.:
raise ValueError(messages.MESH_LARGE)
try:
np.arange(int(self.interface.alpha / self.interface.target_mesh))
except BaseException:
print(("Error while initializing ITIM: alpha ({0:f}) too large or\
mesh ({1:f}) too small".format(self.interface.alpha,
self.interface.target_mesh)))
raise ValueError
示例6: guess_normal
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def guess_normal(universe, group):
"""
Guess the normal of a liquid slab
"""
universe.atoms.pack_into_box()
dim = universe.coord.dimensions
delta = []
for direction in range(0, 3):
histo, _ = np.histogram(
group.positions[:, direction],
bins=5,
range=(0, dim[direction]),
density=True)
max_val = np.amax(histo)
min_val = np.amin(histo)
delta.append(np.sqrt((max_val - min_val)**2))
if np.max(delta) / np.min(delta) < 5.0:
print("Warning: the result of the automatic normal detection (",
np.argmax(delta), ") is not reliable")
return np.argmax(delta)
示例7: refine_room_region
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def refine_room_region(cw_mask, rm_ind):
label_rm, num_label = ndimage.label((1-cw_mask))
new_rm_ind = np.zeros(rm_ind.shape)
for j in xrange(1, num_label+1):
mask = (label_rm == j).astype(np.uint8)
ys, xs = np.where(mask!=0)
area = (np.amax(xs)-np.amin(xs))*(np.amax(ys)-np.amin(ys))
if area < 100:
continue
else:
room_types, type_counts = np.unique(mask*rm_ind, return_counts=True)
if len(room_types) > 1:
room_types = room_types[1:] # ignore background type which is zero
type_counts = type_counts[1:] # ignore background count
new_rm_ind += mask*room_types[np.argmax(type_counts)]
return new_rm_ind
示例8: discrete_ackley
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def discrete_ackley(vector):
# takes k-dimensional vector
vector = np.array(vector)
vector = 100 * vector - 50
bounds = [1.0, 2.0, 3.0, 4.0, 5.0]
bounds = np.array(bounds)**2
result = 5
for bound in bounds[::-1]:
if np.amax(np.abs(vector)) < bound:
result -= 1
bounds = [1.25, 2.0, 2.5]
bounds = np.array(bounds)**2
domain = np.linspace(-50, 50, 10)
dx = domain[1] - domain[0]
imaged = np.array([np.amin(np.abs(element - domain)) for element in vector])
new_res = 5
for bound in bounds[::-1]:
if np.amax(np.abs(imaged)) < bound:
new_res -= 1
result = np.amin([result, new_res])
result = np.amin([4, result])
return result
示例9: discrete_michalewicz
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def discrete_michalewicz(vector):
vector = np.array(vector)
vector = 100 * vector - 40
bounds = [1.0, 2.0, 3.0, 4.0, 5.0]
bounds = np.array(bounds)**2
result = 5
for bound in bounds[::-1]:
if np.amax(np.abs(vector)) < bound:
result -= 1
bounds = [1.25, 2.0, 2.5, 3.0]
bounds = np.array(bounds)**2
new_res = 5
for bound in bounds[::-1]:
if np.amin(np.abs(vector)) < bound:
new_res -= 1
result = np.amin([result, new_res, 4])
return result
示例10: _generate_sampled
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def _generate_sampled(self, num_samples, observ_dict):
# clean observations
obs_params, obs_losses = self.observation_parser.parse(observ_dict)
lowest_loss = np.amin(obs_losses)
lowest_params = obs_params[np.argmin(obs_losses)]
self.obs_params, self.obs_losses = self.observation_parser._raw_obs_params, self.observation_parser._raw_obs_losses
self._compute_characteristic_distances()
# create and sample the model
print('# running density estimation')
self.network = BayesianNeuralNetwork(self.var_dicts, obs_params, obs_losses, self.param_dict['general']['batch_size'], backend = self.param_dict['general']['backend'])
self.network.create_model()
self.network.sample()
self.network.build_penalties()
# sample the acquisition function
print('# proposing new samples')
self.proposed_samples = self.acq_func_sampler.sample(lowest_params, self.network.penalty_contributions,
self.network.lambda_values, parallel = self.param_dict['general']['parallel_evaluations'])
示例11: rescale_losses
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def rescale_losses(self, losses):
for index in range(losses.shape[1]):
min_loss, max_loss = np.amin(losses[:, index]), np.amax(losses[:, index])
losses[:, index] = (losses[:, index] - min_loss) / (max_loss - min_loss)
losses = np.where(np.isnan(losses), 0., losses)
# print(losses.shape)
# quit()
self.unscaled_losses = losses.transpose()
self._build_tolerances()
self._construct_objective()
return self.loss.transpose()
#========================================================================
示例12: test_state_aggregation_modes
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def test_state_aggregation_modes(self):
"""Tests that all state updates tensors can be aggregated."""
x_fn = lambda: tf.random.uniform((5,))
encoder = gather_encoder.GatherEncoder.from_encoder(
core_encoder.EncoderComposer(
test_utils.StateUpdateTensorsEncodingStage()).make(),
tf.TensorSpec.from_tensor(x_fn()))
iteration = _make_iteration_function(encoder, x_fn, 3)
data = self.evaluate(iteration(encoder.initial_state()))
expected_sum = np.sum(data.x)
expected_min = np.amin(data.x)
expected_max = np.amax(data.x)
expected_stack_values = 15 # 3 values of shape 5.
expected_state = [
expected_sum, expected_min, expected_max, expected_stack_values
]
# We are not in control of ordering of the elements in state tuple.
self.assertAllClose(sorted(expected_state), sorted(data.updated_state))
示例13: step
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def step(self, action):
action = action.ravel()
a_lb, a_ub = self.action_space.bounds
action = np.clip(action, a_lb, a_ub).ravel()
next_obs = self.dynamics.forward(self.observation, action)
o_lb, o_ub = self.observation_space.bounds
next_obs = np.clip(next_obs, o_lb, o_ub)
reward = self.compute_reward(self.observation, action)
cur_position = self.observation
dist_to_goal = np.amin([
np.linalg.norm(cur_position - goal_position)
for goal_position in self.goal_positions
])
done = dist_to_goal < self.goal_threshold
if done:
reward += self.goal_reward
self.observation = np.copy(next_obs)
return next_obs, reward, done, {'pos': next_obs}
示例14: compute_reward
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def compute_reward(self, observation, action):
# penalize the L2 norm of acceleration
# noinspection PyTypeChecker
action_cost = np.sum(action ** 2) * self.action_cost_coeff
# penalize squared dist to goal
cur_position = observation
# noinspection PyTypeChecker
goal_cost = np.amin([
np.sum((cur_position - goal_position) ** 2)
for goal_position in self.goal_positions
])
# penalize staying with the log barriers
costs = [action_cost, goal_cost]
reward = -np.sum(costs)
return reward
示例15: plot_position_cost
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import amin [as 別名]
def plot_position_cost(self, ax):
delta = 0.01
x_min, x_max = tuple(1.1 * np.array(self.xlim))
y_min, y_max = tuple(1.1 * np.array(self.ylim))
X, Y = np.meshgrid(
np.arange(x_min, x_max, delta),
np.arange(y_min, y_max, delta)
)
goal_costs = np.amin([
(X - goal_x) ** 2 + (Y - goal_y) ** 2
for goal_x, goal_y in self.goal_positions
], axis=0)
costs = goal_costs
contours = ax.contour(X, Y, costs, 20)
ax.clabel(contours, inline=1, fontsize=10, fmt='%.0f')
ax.set_xlim([x_min, x_max])
ax.set_ylim([y_min, y_max])
goal = ax.plot(self.goal_positions[:, 0],
self.goal_positions[:, 1], 'ro')
return [contours, goal]