本文整理匯總了Python中numpy.logical_not方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.logical_not方法的具體用法?Python numpy.logical_not怎麽用?Python numpy.logical_not使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.logical_not方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_subsample_all_examples
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_subsample_all_examples(self):
numpy_labels = np.random.permutation(300)
indicator = tf.constant(np.ones(300) == 1)
numpy_labels = (numpy_labels - 200) > 0
labels = tf.constant(numpy_labels)
sampler = (balanced_positive_negative_sampler.
BalancedPositiveNegativeSampler())
is_sampled = sampler.subsample(indicator, 64, labels)
with self.test_session() as sess:
is_sampled = sess.run(is_sampled)
self.assertTrue(sum(is_sampled) == 64)
self.assertTrue(sum(np.logical_and(numpy_labels, is_sampled)) == 32)
self.assertTrue(sum(np.logical_and(
np.logical_not(numpy_labels), is_sampled)) == 32)
示例2: test_subsample_selection
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_subsample_selection(self):
# Test random sampling when only some examples can be sampled:
# 100 samples, 20 positives, 10 positives cannot be sampled
numpy_labels = np.arange(100)
numpy_indicator = numpy_labels < 90
indicator = tf.constant(numpy_indicator)
numpy_labels = (numpy_labels - 80) >= 0
labels = tf.constant(numpy_labels)
sampler = (balanced_positive_negative_sampler.
BalancedPositiveNegativeSampler())
is_sampled = sampler.subsample(indicator, 64, labels)
with self.test_session() as sess:
is_sampled = sess.run(is_sampled)
self.assertTrue(sum(is_sampled) == 64)
self.assertTrue(sum(np.logical_and(numpy_labels, is_sampled)) == 10)
self.assertTrue(sum(np.logical_and(
np.logical_not(numpy_labels), is_sampled)) == 54)
self.assertAllEqual(is_sampled, np.logical_and(is_sampled,
numpy_indicator))
示例3: _get_result_map
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def _get_result_map(self, mask):
"""Processing mask data"""
# mask.shape[0]: row, mask.shape[1]: column
result_map = np.zeros((mask.shape[1], mask.shape[0], self.nb_classes))
# 0 (background pixel), 128 (face area pixel) or 255 (hair area pixel).
skin = (mask == 128)
hair = (mask == 255)
if self.nb_classes == 2:
# hair = (mask > 128)
background = np.logical_not(hair)
result_map[:, :, 0] = np.where(background, 1, 0)
result_map[:, :, 1] = np.where(hair, 1, 0)
elif self.nb_classes == 3:
background = np.logical_not(hair + skin)
result_map[:, :, 0] = np.where(background, 1, 0)
result_map[:, :, 1] = np.where(skin, 1, 0)
result_map[:, :, 2] = np.where(hair, 1, 0)
else:
raise Exception("error...")
return result_map
開發者ID:JACKYLUO1991,項目名稱:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代碼行數:25,代碼來源:data_loader.py
示例4: find_outliers_upper_tail
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def find_outliers_upper_tail(mu):
# remove values that are nan
I = np.where(np.logical_and(np.logical_not(np.isnan(mu)), np.logical_not(np.isinf(mu))))[0]
mu = mu[I]
# calculate mean and sigma
mean, sigma = mu.mean(), mu.std()
# calculate the deviation in terms of sigma
deviation = (mu - mean) / sigma
# 2 * sigma is considered as an outlier
S = I[np.where(deviation >= 2)[0]]
if len(S) == 0 and deviation.max() > 1:
S = I[[np.argmax(mu)]]
return S if len(S) > 0 else None
示例5: test_class
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_class(self):
"""Tests container behavior."""
model = kproxy_supercell.TDProxy(self.model_krhf, "hf", [self.k, 1, 1], density_fitting_hf)
model.nroots = self.td_model_krhf.nroots
assert not model.fast
model.kernel()
testing.assert_allclose(model.e, self.td_model_krhf.e, atol=1e-5)
# Test real
testing.assert_allclose(model.e.imag, 0, atol=1e-8)
nocc = nvirt = 4
testing.assert_equal(model.xy.shape, (len(model.e), 2, self.k, self.k, nocc, nvirt))
# Test only non-degenerate roots
d = abs(model.e[1:] - model.e[:-1]) < 1e-8
d = numpy.logical_or(numpy.concatenate(([False], d)), numpy.concatenate((d, [False])))
d = numpy.logical_not(d)
assert_vectors_close(self.td_model_krhf.xy[d], model.xy[d], atol=1e-5)
示例6: _node_regr
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def _node_regr(self, configs, wf):
"""
Return true if a given configuration is within nodal_cutoff
of the node
Also return the regularization polynomial if true,
f = a * r ** 2 + b * r ** 4 + c * r ** 3
"""
ne = configs.configs.shape[1]
d2 = 0.0
for e in range(ne):
d2 += np.sum(wf.gradient(e, configs.electron(e)) ** 2, axis=0)
r = 1.0 / d2
mask = r < self.nodal_cutoff ** 2
c = 7.0 / (self.nodal_cutoff ** 6)
b = -15.0 / (self.nodal_cutoff ** 4)
a = 9.0 / (self.nodal_cutoff ** 2)
f = a * r + b * r ** 2 + c * r ** 3
f[np.logical_not(mask)] = 1.0
return mask, f
示例7: color_pcl
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def color_pcl(pcl, K, im, color_axis=0, as_int=True, invalid_color=[0,0,0]):
uvd = K @ pcl.T
uvd /= uvd[2]
uvd = np.round(uvd).astype(np.int32)
mask = np.logical_and(uvd[0] >= 0, uvd[1] >= 0)
color = np.empty((pcl.shape[0], 3), dtype=im.dtype)
if color_axis == 0:
mask = np.logical_and(mask, uvd[0] < im.shape[2])
mask = np.logical_and(mask, uvd[1] < im.shape[1])
uvd = uvd[:,mask]
color[mask,:] = im[:,uvd[1],uvd[0]].T
elif color_axis == 2:
mask = np.logical_and(mask, uvd[0] < im.shape[1])
mask = np.logical_and(mask, uvd[1] < im.shape[0])
uvd = uvd[:,mask]
color[mask,:] = im[uvd[1],uvd[0], :]
else:
raise Exception('invalid color_axis')
color[np.logical_not(mask),:3] = invalid_color
if as_int:
color = (255.0 * color).astype(np.int32)
return color
示例8: test_subsample_all_examples_dynamic
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_subsample_all_examples_dynamic(self):
numpy_labels = np.random.permutation(300)
indicator = tf.constant(np.ones(300) == 1)
numpy_labels = (numpy_labels - 200) > 0
labels = tf.constant(numpy_labels)
sampler = (
balanced_positive_negative_sampler.BalancedPositiveNegativeSampler())
is_sampled = sampler.subsample(indicator, 64, labels)
with self.test_session() as sess:
is_sampled = sess.run(is_sampled)
self.assertTrue(sum(is_sampled) == 64)
self.assertTrue(sum(np.logical_and(numpy_labels, is_sampled)) == 32)
self.assertTrue(sum(np.logical_and(
np.logical_not(numpy_labels), is_sampled)) == 32)
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:18,代碼來源:balanced_positive_negative_sampler_test.py
示例9: test_subsample_all_examples_static
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_subsample_all_examples_static(self):
numpy_labels = np.random.permutation(300)
indicator = np.array(np.ones(300) == 1, np.bool)
numpy_labels = (numpy_labels - 200) > 0
labels = np.array(numpy_labels, np.bool)
def graph_fn(indicator, labels):
sampler = (
balanced_positive_negative_sampler.BalancedPositiveNegativeSampler(
is_static=True))
return sampler.subsample(indicator, 64, labels)
is_sampled = self.execute(graph_fn, [indicator, labels])
self.assertTrue(sum(is_sampled) == 64)
self.assertTrue(sum(np.logical_and(numpy_labels, is_sampled)) == 32)
self.assertTrue(sum(np.logical_and(
np.logical_not(numpy_labels), is_sampled)) == 32)
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:20,代碼來源:balanced_positive_negative_sampler_test.py
示例10: test_subsample_selection_dynamic
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_subsample_selection_dynamic(self):
# Test random sampling when only some examples can be sampled:
# 100 samples, 20 positives, 10 positives cannot be sampled
numpy_labels = np.arange(100)
numpy_indicator = numpy_labels < 90
indicator = tf.constant(numpy_indicator)
numpy_labels = (numpy_labels - 80) >= 0
labels = tf.constant(numpy_labels)
sampler = (
balanced_positive_negative_sampler.BalancedPositiveNegativeSampler())
is_sampled = sampler.subsample(indicator, 64, labels)
with self.test_session() as sess:
is_sampled = sess.run(is_sampled)
self.assertTrue(sum(is_sampled) == 64)
self.assertTrue(sum(np.logical_and(numpy_labels, is_sampled)) == 10)
self.assertTrue(sum(np.logical_and(
np.logical_not(numpy_labels), is_sampled)) == 54)
self.assertAllEqual(is_sampled, np.logical_and(is_sampled,
numpy_indicator))
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:23,代碼來源:balanced_positive_negative_sampler_test.py
示例11: test_subsample_selection_static
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_subsample_selection_static(self):
# Test random sampling when only some examples can be sampled:
# 100 samples, 20 positives, 10 positives cannot be sampled.
numpy_labels = np.arange(100)
numpy_indicator = numpy_labels < 90
indicator = np.array(numpy_indicator, np.bool)
numpy_labels = (numpy_labels - 80) >= 0
labels = np.array(numpy_labels, np.bool)
def graph_fn(indicator, labels):
sampler = (
balanced_positive_negative_sampler.BalancedPositiveNegativeSampler(
is_static=True))
return sampler.subsample(indicator, 64, labels)
is_sampled = self.execute(graph_fn, [indicator, labels])
self.assertTrue(sum(is_sampled) == 64)
self.assertTrue(sum(np.logical_and(numpy_labels, is_sampled)) == 10)
self.assertTrue(sum(np.logical_and(
np.logical_not(numpy_labels), is_sampled)) == 54)
self.assertAllEqual(is_sampled, np.logical_and(is_sampled, numpy_indicator))
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:24,代碼來源:balanced_positive_negative_sampler_test.py
示例12: test_subsample_selection_larger_batch_size_static
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_subsample_selection_larger_batch_size_static(self):
# Test random sampling when total number of examples that can be sampled are
# less than batch size:
# 100 samples, 50 positives, 40 positives cannot be sampled, batch size 64.
# It should still return 64 samples, with 4 of them that couldn't have been
# sampled.
numpy_labels = np.arange(100)
numpy_indicator = numpy_labels < 60
indicator = np.array(numpy_indicator, np.bool)
numpy_labels = (numpy_labels - 50) >= 0
labels = np.array(numpy_labels, np.bool)
def graph_fn(indicator, labels):
sampler = (
balanced_positive_negative_sampler.BalancedPositiveNegativeSampler(
is_static=True))
return sampler.subsample(indicator, 64, labels)
is_sampled = self.execute(graph_fn, [indicator, labels])
self.assertTrue(sum(is_sampled) == 64)
self.assertTrue(sum(np.logical_and(numpy_labels, is_sampled)) >= 10)
self.assertTrue(
sum(np.logical_and(np.logical_not(numpy_labels), is_sampled)) >= 50)
self.assertTrue(sum(np.logical_and(is_sampled, numpy_indicator)) == 60)
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:27,代碼來源:balanced_positive_negative_sampler_test.py
示例13: test_subsample_selection_no_batch_size
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_subsample_selection_no_batch_size(self):
# Test random sampling when only some examples can be sampled:
# 1000 samples, 6 positives (5 can be sampled).
numpy_labels = np.arange(1000)
numpy_indicator = numpy_labels < 999
indicator = tf.constant(numpy_indicator)
numpy_labels = (numpy_labels - 994) >= 0
labels = tf.constant(numpy_labels)
sampler = (balanced_positive_negative_sampler.
BalancedPositiveNegativeSampler(0.01))
is_sampled = sampler.subsample(indicator, None, labels)
with self.test_session() as sess:
is_sampled = sess.run(is_sampled)
self.assertTrue(sum(is_sampled) == 500)
self.assertTrue(sum(np.logical_and(numpy_labels, is_sampled)) == 5)
self.assertTrue(sum(np.logical_and(
np.logical_not(numpy_labels), is_sampled)) == 495)
self.assertAllEqual(is_sampled, np.logical_and(is_sampled,
numpy_indicator))
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:23,代碼來源:balanced_positive_negative_sampler_test.py
示例14: test_2d_with_missing
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_2d_with_missing(self):
# Test cov on 2D variable w/ missing value
x = self.data
x[-1] = masked
x = x.reshape(3, 4)
valid = np.logical_not(getmaskarray(x)).astype(int)
frac = np.dot(valid, valid.T)
xf = (x - x.mean(1)[:, None]).filled(0)
assert_almost_equal(cov(x),
np.cov(xf) * (x.shape[1] - 1) / (frac - 1.))
assert_almost_equal(cov(x, bias=True),
np.cov(xf, bias=True) * x.shape[1] / frac)
frac = np.dot(valid.T, valid)
xf = (x - x.mean(0)).filled(0)
assert_almost_equal(cov(x, rowvar=False),
(np.cov(xf, rowvar=False) *
(x.shape[0] - 1) / (frac - 1.)))
assert_almost_equal(cov(x, rowvar=False, bias=True),
(np.cov(xf, rowvar=False, bias=True) *
x.shape[0] / frac))
示例15: test_object_logical
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import logical_not [as 別名]
def test_object_logical(self):
a = np.array([3, None, True, False, "test", ""], dtype=object)
assert_equal(np.logical_or(a, None),
np.array([x or None for x in a], dtype=object))
assert_equal(np.logical_or(a, True),
np.array([x or True for x in a], dtype=object))
assert_equal(np.logical_or(a, 12),
np.array([x or 12 for x in a], dtype=object))
assert_equal(np.logical_or(a, "blah"),
np.array([x or "blah" for x in a], dtype=object))
assert_equal(np.logical_and(a, None),
np.array([x and None for x in a], dtype=object))
assert_equal(np.logical_and(a, True),
np.array([x and True for x in a], dtype=object))
assert_equal(np.logical_and(a, 12),
np.array([x and 12 for x in a], dtype=object))
assert_equal(np.logical_and(a, "blah"),
np.array([x and "blah" for x in a], dtype=object))
assert_equal(np.logical_not(a),
np.array([not x for x in a], dtype=object))
assert_equal(np.logical_or.reduce(a), 3)
assert_equal(np.logical_and.reduce(a), None)