本文整理汇总了Python中numpy.invert方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.invert方法的具体用法?Python numpy.invert怎么用?Python numpy.invert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.invert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: eval_batch
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def eval_batch(table_batch, label_batch, mask_batch):
# reshap (table_batch * table_size * features)
for f_g in table_batch:
table_batch[f_g] = table_batch[f_g].view(batch_size * MAX_COL_COUNT, -1)
emissions = classifier(table_batch).view(batch_size, MAX_COL_COUNT, -1)
pred = model.decode(emissions, mask_batch)
pred = np.concatenate(pred)
labels = label_batch.view(-1).cpu().numpy()
masks = mask_batch.view(-1).cpu().numpy()
invert_masks = np.invert(masks==1)
return pred, ma.array(labels, mask=invert_masks).compressed()
# randomly shuffle the orders of columns in a table batch
示例2: test_ufunc_at_manual
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def test_ufunc_at_manual(self):
def check(ufunc, a, ind, b=None):
a0 = a.copy()
if b is None:
ufunc.at(a0, ind.copy())
c1 = a0.copy()
ufunc.at(a, ind)
c2 = a.copy()
else:
ufunc.at(a0, ind.copy(), b.copy())
c1 = a0.copy()
ufunc.at(a, ind, b)
c2 = a.copy()
assert_array_equal(c1, c2)
# Overlap with index
a = np.arange(10000, dtype=np.int16)
check(np.invert, a[::-1], a)
# Overlap with second data array
a = np.arange(100, dtype=np.int16)
ind = np.arange(0, 100, 2, dtype=np.int16)
check(np.add, a, ind, a[25:75])
示例3: map_charades
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def map_charades(y_true, y_pred):
""" Returns mAP """
m_aps = []
n_classes = y_pred.shape[1]
for oc_i in range(n_classes):
pred_row = y_pred[:, oc_i]
sorted_idxs = np.argsort(-pred_row)
true_row = y_true[:, oc_i]
tp = true_row[sorted_idxs] == 1
fp = np.invert(tp)
n_pos = tp.sum()
if n_pos < 0.1:
m_aps.append(float('nan'))
continue
f_pcs = np.cumsum(fp)
t_pcs = np.cumsum(tp)
prec = t_pcs / (f_pcs + t_pcs).astype(float)
avg_prec = 0
for i in range(y_pred.shape[0]):
if tp[i]:
avg_prec += prec[i]
m_aps.append(avg_prec / n_pos.astype(float))
m_aps = np.array(m_aps)
m_ap = np.mean(m_aps)
return m_ap
示例4: invert
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def invert(data):
"""
Inverts the byte data it received utilizing an XOR operation.
:param data: A chunk of byte data
:return inverted: The same size of chunked data inverted bitwise
"""
# Convert the bytestring into an integer
intwave = np.fromstring(data, np.int32)
# Invert the integer
intwave = np.invert(intwave)
# Convert the integer back into a bytestring
inverted = np.frombuffer(intwave, np.byte)
# Return the inverted audio data
return inverted
示例5: gen_mask_array
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def gen_mask_array(icon_dir: str, invert_mask: bool, size: int):
"""Generates a numpy array of an icon mask."""
icon = Image.open(os.path.join(icon_dir, "icon.png"))
if isinstance(size, int):
size = (size, size)
# https://stackoverflow.com/a/2563883
icon_w, icon_h = icon.size
icon_mask = Image.new("RGBA", icon.size, (255, 255, 255, 255))
icon_mask.paste(icon, icon)
mask = Image.new("RGBA", size, (255, 255, 255, 255))
mask_w, mask_h = mask.size
offset = ((mask_w - icon_w) // 2, (mask_h - icon_h) // 2)
mask.paste(icon_mask, offset)
mask_array = np.array(mask, dtype="uint8")
if invert_mask:
mask_array = np.invert(mask_array)
return mask_array
示例6: augment_occlusion_mask
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def augment_occlusion_mask(self, masks, verbose=False, min_trans = 0.2, max_trans=0.7, max_occl = 0.25,min_occl = 0.0):
new_masks = np.zeros_like(masks,dtype=np.bool)
occl_masks_batch = self.random_syn_masks[np.random.choice(len(self.random_syn_masks),len(masks))]
for idx,mask in enumerate(masks):
occl_mask = occl_masks_batch[idx]
while True:
trans_x = int(np.random.choice([-1,1])*(np.random.rand()*(max_trans-min_trans) + min_trans)*occl_mask.shape[0])
trans_y = int(np.random.choice([-1,1])*(np.random.rand()*(max_trans-min_trans) + min_trans)*occl_mask.shape[1])
M = np.float32([[1,0,trans_x],[0,1,trans_y]])
transl_occl_mask = cv2.warpAffine(occl_mask,M,(occl_mask.shape[0],occl_mask.shape[1]))
overlap_matrix = np.invert(mask.astype(np.bool)) * transl_occl_mask.astype(np.bool)
overlap = len(overlap_matrix[overlap_matrix==True])/float(len(mask[mask==0]))
if overlap < max_occl and overlap > min_occl:
new_masks[idx,...] = np.logical_xor(mask.astype(np.bool), overlap_matrix)
if verbose:
print('overlap is ', overlap)
break
return new_masks
示例7: degamma_srgb
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def degamma_srgb(self, clip_range=[0, 65535]):
# bring data in range 0 to 1
data = np.clip(self.data, clip_range[0], clip_range[1])
data = np.divide(data, clip_range[1])
data = np.asarray(data)
mask = data > 0.04045
# basically, if data[x, y, c] > 0.04045, data[x, y, c] = ( (data[x, y, c] + 0.055) / 1.055 ) ^ 2.4
# else, data[x, y, c] = data[x, y, c] / 12.92
data[mask] += 0.055
data[mask] /= 1.055
data[mask] **= 2.4
data[np.invert(mask)] /= 12.92
# rescale
return np.clip(data * clip_range[1], clip_range[0], clip_range[1])
示例8: gamma_srgb
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def gamma_srgb(self, clip_range=[0, 65535]):
# bring data in range 0 to 1
data = np.clip(self.data, clip_range[0], clip_range[1])
data = np.divide(data, clip_range[1])
data = np.asarray(data)
mask = data > 0.0031308
# basically, if data[x, y, c] > 0.0031308, data[x, y, c] = 1.055 * ( var_R(i, j) ^ ( 1 / 2.4 ) ) - 0.055
# else, data[x, y, c] = data[x, y, c] * 12.92
data[mask] **= 0.4167
data[mask] *= 1.055
data[mask] -= 0.055
data[np.invert(mask)] *= 12.92
# rescale
return np.clip(data * clip_range[1], clip_range[0], clip_range[1])
示例9: xyz2lab
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def xyz2lab(self, cie_version="1931", illuminant="d65"):
xyz_reference = helpers().get_xyz_reference(cie_version, illuminant)
data = self.data
data[:, :, 0] = data[:, :, 0] / xyz_reference[0]
data[:, :, 1] = data[:, :, 1] / xyz_reference[1]
data[:, :, 2] = data[:, :, 2] / xyz_reference[2]
data = np.asarray(data)
# if data[x, y, c] > 0.008856, data[x, y, c] = data[x, y, c] ^ (1/3)
# else, data[x, y, c] = 7.787 * data[x, y, c] + 16/116
mask = data > 0.008856
data[mask] **= 1./3.
data[np.invert(mask)] *= 7.787
data[np.invert(mask)] += 16./116.
data = np.float32(data)
output = np.empty(np.shape(self.data), dtype=np.float32)
output[:, :, 0] = 116. * data[:, :, 1] - 16.
output[:, :, 1] = 500. * (data[:, :, 0] - data[:, :, 1])
output[:, :, 2] = 200. * (data[:, :, 1] - data[:, :, 2])
return output
示例10: lab2xyz
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def lab2xyz(self, cie_version="1931", illuminant="d65"):
output = np.empty(np.shape(self.data), dtype=np.float32)
output[:, :, 1] = (self.data[:, :, 0] + 16.) / 116.
output[:, :, 0] = (self.data[:, :, 1] / 500.) + output[:, :, 1]
output[:, :, 2] = output[:, :, 1] - (self.data[:, :, 2] / 200.)
# if output[x, y, c] > 0.008856, output[x, y, c] ^ 3
# else, output[x, y, c] = ( output[x, y, c] - 16/116 ) / 7.787
output = np.asarray(output)
mask = output > 0.008856
output[mask] **= 3.
output[np.invert(mask)] -= 16/116
output[np.invert(mask)] /= 7.787
xyz_reference = helpers().get_xyz_reference(cie_version, illuminant)
output = np.float32(output)
output[:, :, 0] = output[:, :, 0] * xyz_reference[0]
output[:, :, 1] = output[:, :, 1] * xyz_reference[1]
output[:, :, 2] = output[:, :, 2] * xyz_reference[2]
return output
示例11: create_test_set
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def create_test_set(x_lst):
n = len(x_lst)
x_lens = np.array(map(len, x_lst))
max_len = max(map(len, x_lst)) - 1
u_out = np.zeros((n, max_len, OUTDIM), dtype='float32')*np.nan
x_out = np.zeros((n, max_len, OUTDIM), dtype='float32')*np.nan
for row, vec in enumerate(x_lst):
l = len(vec) - 1
u = vec[:-1] # all but last element
x = vec[1:] # all but first element
x_out[row, :l] = x
u_out[row, :l] = u
mask = np.invert(np.isnan(x_out))
x_out[np.isnan(x_out)] = 0
u_out[np.isnan(u_out)] = 0
mask = mask[:, :, 0]
assert np.all((mask.sum(axis=1)+1) == x_lens)
return u_out, x_out, mask.astype('float32')
示例12: get_map_to_predict
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def get_map_to_predict(src_locs, src_x_axiss, src_y_axiss, map, map_size,
interpolation=cv2.INTER_LINEAR):
fss = []
valids = []
center = (map_size-1.0)/2.0
dst_theta = np.pi/2.0
dst_loc = np.array([center, center])
dst_x_axis = np.array([np.cos(dst_theta), np.sin(dst_theta)])
dst_y_axis = np.array([np.cos(dst_theta+np.pi/2), np.sin(dst_theta+np.pi/2)])
def compute_points(center, x_axis, y_axis):
points = np.zeros((3,2),dtype=np.float32)
points[0,:] = center
points[1,:] = center + x_axis
points[2,:] = center + y_axis
return points
dst_points = compute_points(dst_loc, dst_x_axis, dst_y_axis)
for i in range(src_locs.shape[0]):
src_loc = src_locs[i,:]
src_x_axis = src_x_axiss[i,:]
src_y_axis = src_y_axiss[i,:]
src_points = compute_points(src_loc, src_x_axis, src_y_axis)
M = cv2.getAffineTransform(src_points, dst_points)
fs = cv2.warpAffine(map, M, (map_size, map_size), None, flags=interpolation,
borderValue=np.NaN)
valid = np.invert(np.isnan(fs))
valids.append(valid)
fss.append(fs)
return fss, valids
示例13: solve_with_covariance_matrices
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def solve_with_covariance_matrices(self, Z, Y):
A = np.cov(Z.T)
B = np.cov(Z.T, Y.T)
W = np.invert(A) @ B
self.layers[-1].set_weights([W, np.array([0] * self.layers[-1].neurons)], fold=False)
示例14: eval_batch
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def eval_batch(classifier, model, val_dataset, batch_size, device, n_worker, MAX_COL_COUNT):
validation = datasets.generate_batches(val_dataset,
batch_size=batch_size,
shuffle=False,
drop_last=True,
device=device,
n_workers=n_worker)
y_pred, y_true = [], []
for table_batch, label_batch, mask_batch in tqdm(validation):
#pred, labels = eval_batch(table_batch, label_batch, mask_batch)
# reshap (table_batch * table_size * features)
for f_g in table_batch:
table_batch[f_g] = table_batch[f_g].view(batch_size * MAX_COL_COUNT, -1)
emissions = classifier(table_batch).view(batch_size, MAX_COL_COUNT, -1)
pred = model.decode(emissions, mask_batch)
pred = np.concatenate(pred)
labels = label_batch.view(-1).cpu().numpy()
masks = mask_batch.view(-1).cpu().numpy()
invert_masks = np.invert(masks==1)
y_pred.extend(pred)
y_true.extend(ma.array(labels, mask=invert_masks).compressed())
val_acc = classification_report(y_true, y_pred, output_dict=True)
return val_acc
示例15: _in1d_dispatcher
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import invert [as 别名]
def _in1d_dispatcher(ar1, ar2, assume_unique=None, invert=None):
return (ar1, ar2)