本文整理汇总了Python中numpy.histogramdd方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.histogramdd方法的具体用法?Python numpy.histogramdd怎么用?Python numpy.histogramdd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.histogramdd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rightmost_binedge
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_rightmost_binedge(self):
# Test event very close to rightmost binedge. See Github issue #4266
x = [0.9999999995]
bins = [[0., 0.5, 1.0]]
hist, _ = histogramdd(x, bins=bins)
assert_(hist[0] == 0.0)
assert_(hist[1] == 1.)
x = [1.0]
bins = [[0., 0.5, 1.0]]
hist, _ = histogramdd(x, bins=bins)
assert_(hist[0] == 0.0)
assert_(hist[1] == 1.)
x = [1.0000000001]
bins = [[0., 0.5, 1.0]]
hist, _ = histogramdd(x, bins=bins)
assert_(hist[0] == 0.0)
assert_(hist[1] == 0.0)
x = [1.0001]
bins = [[0., 0.5, 1.0]]
hist, _ = histogramdd(x, bins=bins)
assert_(hist[0] == 0.0)
assert_(hist[1] == 0.0)
示例2: calc_tvd
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def calc_tvd(sess,Generator,Data,N=50000,nbins=10):
Xd=sess.run(Data.X,{Data.N:N})
step,Xg=sess.run([Generator.step,Generator.X],{Generator.N:N})
p_gen,_ = np.histogramdd(Xg,bins=nbins,range=[[0,1],[0,1],[0,1]],normed=True)
p_dat,_ = np.histogramdd(Xd,bins=nbins,range=[[0,1],[0,1],[0,1]],normed=True)
p_gen/=nbins**3
p_dat/=nbins**3
tvd=0.5*np.sum(np.abs( p_gen-p_dat ))
mvd=np.max(np.abs( p_gen-p_dat ))
return step,tvd, mvd
s_tvd=make_summary(Data.name+'_tvd',tvd)
s_mvd=make_summary(Data.name+'_mvd',mvd)
return step,s_tvd,s_mvd
#return make_summary('tvd/'+Generator.name,tvd)
示例3: test_rightmost_binedge
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_rightmost_binedge(self):
# Test event very close to rightmost binedge. See Github issue #4266
x = [0.9999999995]
bins = [[0., 0.5, 1.0]]
hist, _ = histogramdd(x, bins=bins)
assert_(hist[0] == 0.0)
assert_(hist[1] == 1.)
x = [1.0]
bins = [[0., 0.5, 1.0]]
hist, _ = histogramdd(x, bins=bins)
assert_(hist[0] == 0.0)
assert_(hist[1] == 1.)
x = [1.0000000001]
bins = [[0., 0.5, 1.0]]
hist, _ = histogramdd(x, bins=bins)
assert_(hist[0] == 0.0)
assert_(hist[1] == 1.)
x = [1.0001]
bins = [[0., 0.5, 1.0]]
hist, _ = histogramdd(x, bins=bins)
assert_(hist[0] == 0.0)
assert_(hist[1] == 0.0)
示例4: test_no_params
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_no_params(self):
a = np.array([1, 2, 3, 4, 5])
with self.assertWarns(PrivacyLeakWarning):
res = histogramdd(a)
self.assertIsNotNone(res)
示例5: test_no_range
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_no_range(self):
a = np.array([1, 2, 3, 4, 5])
with self.assertWarns(PrivacyLeakWarning):
res = histogramdd(a, epsilon=2)
self.assertIsNotNone(res)
示例6: test_same_edges
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_same_edges(self):
a = np.array([1, 2, 3, 4, 5])
_, edges = np.histogramdd(a, bins=3, range=[(0, 10)])
_, dp_edges = histogramdd(a, epsilon=1, bins=3, range=[(0, 10)])
for i in range(len(edges)):
self.assertTrue((edges[i] == dp_edges[i]).all())
示例7: test_different_result
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_different_result(self):
global_seed(3141592653)
a = np.array([1, 2, 3, 4, 5])
hist, _ = np.histogramdd(a, bins=3, range=[(0, 10)])
dp_hist, _ = histogramdd(a, epsilon=0.1, bins=3, range=[(0, 10)])
# print("Non-private histogram: %s" % hist)
# print("Private histogram: %s" % dp_hist)
self.assertTrue((hist != dp_hist).any())
示例8: test_density_1d
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_density_1d(self):
global_seed(3141592653)
a = np.array([1, 2, 3, 4, 5])
dp_hist, _ = histogramdd(a, epsilon=1, bins=3, range=[(0, 10)], density=True)
# print(dp_hist.sum())
self.assertAlmostEqual(dp_hist.sum(), 1.0 * 3 / 10)
示例9: test_accountant
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_accountant(self):
acc = BudgetAccountant(1.5, 0)
a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]).T
histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True, accountant=acc)
with self.assertRaises(BudgetError):
histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True, accountant=acc)
示例10: test_default_accountant
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_default_accountant(self):
BudgetAccountant.pop_default()
a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]).T
histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True)
acc = BudgetAccountant.pop_default()
self.assertEqual((1, 0), acc.total())
self.assertEqual(acc.epsilon, float("inf"))
self.assertEqual(acc.delta, 1.0)
histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)])
self.assertEqual((1, 0), acc.total())
示例11: test_histogramdd_too_many_bins
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_histogramdd_too_many_bins(self):
# Ticket 928.
assert_raises(ValueError, np.histogramdd, np.ones((1, 10)), bins=2**10)
示例12: test_simple
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_simple(self):
x = np.array([[-.5, .5, 1.5], [-.5, 1.5, 2.5], [-.5, 2.5, .5],
[.5, .5, 1.5], [.5, 1.5, 2.5], [.5, 2.5, 2.5]])
H, edges = histogramdd(x, (2, 3, 3),
range=[[-1, 1], [0, 3], [0, 3]])
answer = np.array([[[0, 1, 0], [0, 0, 1], [1, 0, 0]],
[[0, 1, 0], [0, 0, 1], [0, 0, 1]]])
assert_array_equal(H, answer)
# Check normalization
ed = [[-2, 0, 2], [0, 1, 2, 3], [0, 1, 2, 3]]
H, edges = histogramdd(x, bins=ed, density=True)
assert_(np.all(H == answer / 12.))
# Check that H has the correct shape.
H, edges = histogramdd(x, (2, 3, 4),
range=[[-1, 1], [0, 3], [0, 4]],
density=True)
answer = np.array([[[0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0]],
[[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0]]])
assert_array_almost_equal(H, answer / 6., 4)
# Check that a sequence of arrays is accepted and H has the correct
# shape.
z = [np.squeeze(y) for y in np.split(x, 3, axis=1)]
H, edges = histogramdd(
z, bins=(4, 3, 2), range=[[-2, 2], [0, 3], [0, 2]])
answer = np.array([[[0, 0], [0, 0], [0, 0]],
[[0, 1], [0, 0], [1, 0]],
[[0, 1], [0, 0], [0, 0]],
[[0, 0], [0, 0], [0, 0]]])
assert_array_equal(H, answer)
Z = np.zeros((5, 5, 5))
Z[list(range(5)), list(range(5)), list(range(5))] = 1.
H, edges = histogramdd([np.arange(5), np.arange(5), np.arange(5)], 5)
assert_array_equal(H, Z)
示例13: test_shape_3d
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_shape_3d(self):
# All possible permutations for bins of different lengths in 3D.
bins = ((5, 4, 6), (6, 4, 5), (5, 6, 4), (4, 6, 5), (6, 5, 4),
(4, 5, 6))
r = np.random.rand(10, 3)
for b in bins:
H, edges = histogramdd(r, b)
assert_(H.shape == b)
示例14: test_shape_4d
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_shape_4d(self):
# All possible permutations for bins of different lengths in 4D.
bins = ((7, 4, 5, 6), (4, 5, 7, 6), (5, 6, 4, 7), (7, 6, 5, 4),
(5, 7, 6, 4), (4, 6, 7, 5), (6, 5, 7, 4), (7, 5, 4, 6),
(7, 4, 6, 5), (6, 4, 7, 5), (6, 7, 5, 4), (4, 6, 5, 7),
(4, 7, 5, 6), (5, 4, 6, 7), (5, 7, 4, 6), (6, 7, 4, 5),
(6, 5, 4, 7), (4, 7, 6, 5), (4, 5, 6, 7), (7, 6, 4, 5),
(5, 4, 7, 6), (5, 6, 7, 4), (6, 4, 5, 7), (7, 5, 6, 4))
r = np.random.rand(10, 4)
for b in bins:
H, edges = histogramdd(r, b)
assert_(H.shape == b)
示例15: test_weights
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import histogramdd [as 别名]
def test_weights(self):
v = np.random.rand(100, 2)
hist, edges = histogramdd(v)
n_hist, edges = histogramdd(v, density=True)
w_hist, edges = histogramdd(v, weights=np.ones(100))
assert_array_equal(w_hist, hist)
w_hist, edges = histogramdd(v, weights=np.ones(100) * 2, density=True)
assert_array_equal(w_hist, n_hist)
w_hist, edges = histogramdd(v, weights=np.ones(100, int) * 2)
assert_array_equal(w_hist, 2 * hist)