本文整理汇总了Python中numpy.seterr方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.seterr方法的具体用法?Python numpy.seterr怎么用?Python numpy.seterr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.seterr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def setup(self):
# Base data definition.
x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
a10 = 10.
m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1]
xm = masked_array(x, mask=m1)
ym = masked_array(y, mask=m2)
z = np.array([-.5, 0., .5, .8])
zm = masked_array(z, mask=[0, 1, 0, 0])
xf = np.where(m1, 1e+20, x)
xm.set_fill_value(1e+20)
self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf)
self.err_status = np.geterr()
np.seterr(divide='ignore', invalid='ignore')
示例2: _entropy
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def _entropy(self, *args):
def integ(x):
val = self._pdf(x, *args)
return entr(val)
# upper limit is often inf, so suppress warnings when integrating
olderr = np.seterr(over='ignore')
h = integrate.quad(integ, self.a, self.b)[0]
np.seterr(**olderr)
if not np.isnan(h):
return h
else:
# try with different limits if integration problems
low, upp = self.ppf([1e-10, 1. - 1e-10], *args)
if np.isinf(self.b):
upper = upp
else:
upper = self.b
if np.isinf(self.a):
lower = low
else:
lower = self.a
return integrate.quad(integ, lower, upper)[0]
示例3: setUp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def setUp(self):
# Base data definition.
x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
a10 = 10.
m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1]
xm = masked_array(x, mask=m1)
ym = masked_array(y, mask=m2)
z = np.array([-.5, 0., .5, .8])
zm = masked_array(z, mask=[0, 1, 0, 0])
xf = np.where(m1, 1e+20, x)
xm.set_fill_value(1e+20)
self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf)
self.err_status = np.geterr()
np.seterr(divide='ignore', invalid='ignore')
示例4: evaluate
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def evaluate(self,n, features, stack_float, stack_bool,labels=None):
"""evaluate node in program"""
np.seterr(all='ignore')
if len(stack_float) >= n.arity['f'] and len(stack_bool) >= n.arity['b']:
if n.out_type == 'f':
stack_float.append(
self.safe(self.eval_dict[n.name](n,features,stack_float,
stack_bool,labels)))
if (np.isnan(stack_float[-1]).any() or
np.isinf(stack_float[-1]).any()):
print("problem operator:",n)
else:
stack_bool.append(self.safe(self.eval_dict[n.name](n,features,
stack_float,
stack_bool,
labels)))
if np.isnan(stack_bool[-1]).any() or np.isinf(stack_bool[-1]).any():
print("problem operator:",n)
示例5: with_error_settings
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def with_error_settings(**new_settings):
"""
TODO.
Arguments:
**new_settings: TODO
Returns:
"""
@decorator.decorator
def dec(f, *args, **kwargs):
old_settings = np.geterr()
np.seterr(**new_settings)
ret = f(*args, **kwargs)
np.seterr(**old_settings)
return ret
return dec
示例6: test_basic_stats_generator_no_runtime_warnings_close_to_max_int
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def test_basic_stats_generator_no_runtime_warnings_close_to_max_int(self):
# input has batches with values that are slightly smaller than the maximum
# integer value.
less_than_max_int_value = np.iinfo(np.int64).max - 1
batches = ([
pa.RecordBatch.from_arrays([pa.array([[less_than_max_int_value]])],
['a'])
] * 2)
generator = basic_stats_generator.BasicStatsGenerator()
old_nperr = np.geterr()
np.seterr(over='raise')
accumulators = [
generator.add_input(generator.create_accumulator(), batch)
for batch in batches
]
generator.merge_accumulators(accumulators)
np.seterr(**old_nperr)
示例7: test_get_metrics
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def test_get_metrics(cls):
np.seterr(divide='ignore', invalid='ignore')
bins = 1000
diff = 0.01
metric = MultilabelAveragePrecision(bins=bins)
size = [1000, 100]
pred = Tensor(np.random.uniform(0, 1, size))
gold = Tensor(np.random.randint(0, 2, size))
metric.__call__(pred, gold)
fast_ap = metric.get_metric() # calls the fast get_metric
ap = metric.get_metric(reset=True) # calls the accurate get_metric
assert (abs(ap - fast_ap)) < diff
metric.__call__(pred, gold)
metric.__call__(pred, gold)
metric.__call__(pred, gold)
fast_ap = metric.get_metric()
ap = metric.get_metric(reset=True)
assert (abs(ap - fast_ap)) < diff
示例8: setUp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def setUp (self):
"Base data definition."
x = np.array([1., 1., 1., -2., pi / 2.0, 4., 5., -10., 10., 1., 2., 3.])
y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
a10 = 10.
m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1]
xm = masked_array(x, mask=m1)
ym = masked_array(y, mask=m2)
z = np.array([-.5, 0., .5, .8])
zm = masked_array(z, mask=[0, 1, 0, 0])
xf = np.where(m1, 1e+20, x)
xm.set_fill_value(1e+20)
self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf)
self.err_status = np.geterr()
np.seterr(divide='ignore', invalid='ignore')
示例9: testKMeans
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def testKMeans(self):
random.seed(12345)
numpy.seterr(divide="ignore", invalid="ignore")
dataset = numpy.empty((100000, 3), dtype=numpy.dtype(float))
for i, x in enumerate(TestProducerKMeans.data([1, 1, 1], [3, 2, 5], [8, 2, 7], [5, 8, 5], [1, 1, 9])):
if i >= dataset.shape[0]:
break
dataset[i,:] = x
kmeans = KMeans(5, dataset)
kmeans.optimize(whileall(moving(), maxIterations(1000)))
centers = kmeans.centers()
self.assertArrayAlmostEqual(centers[0], [1.00, 1.01, 1.00], places=2)
self.assertArrayAlmostEqual(centers[1], [1.01, 1.00, 9.01], places=2)
self.assertArrayAlmostEqual(centers[2], [3.01, 2.01, 5.00], places=2)
self.assertArrayAlmostEqual(centers[3], [4.99, 8.00, 4.99], places=2)
self.assertArrayAlmostEqual(centers[4], [8.02, 2.00, 7.01], places=2)
doc = kmeans.pfaDocument("Cluster", ["one", "two", "three", "four", "five"])
# look(doc, maxDepth=8)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][0]["center"], [1.00, 1.01, 1.00], places=2)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][1]["center"], [1.01, 1.00, 9.01], places=2)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][2]["center"], [3.01, 2.01, 5.00], places=2)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][3]["center"], [4.99, 8.00, 4.99], places=2)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][4]["center"], [8.02, 2.00, 7.01], places=2)
engine, = PFAEngine.fromJson(doc)
self.assertEqual(engine.action([1.00, 1.01, 1.00]), "one")
self.assertEqual(engine.action([1.01, 1.00, 9.01]), "two")
self.assertEqual(engine.action([3.01, 2.01, 5.00]), "three")
self.assertEqual(engine.action([4.99, 8.00, 4.99]), "four")
self.assertEqual(engine.action([8.02, 2.00, 7.01]), "five")
示例10: testKMeansTransform
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def testKMeansTransform(self):
random.seed(12345)
numpy.seterr(divide="ignore", invalid="ignore")
dataset = numpy.empty((100000, 3), dtype=numpy.dtype(float))
for i, (x, y, z) in enumerate(TestProducerKMeans.data([1, 1, 1], [3, 2, 5], [8, 2, 7], [5, 8, 5], [1, 1, 9])):
if i >= dataset.shape[0]:
break
dataset[i,:] = [x * 10.0, y * 20.0, z * 30.0]
trans = Transformation("x/10.0", "y/20.0", "z/30.0")
kmeans = KMeans(5, trans.transform(dataset, ["x", "y", "z"]))
kmeans.optimize(whileall(moving(), maxIterations(1000)))
centers = kmeans.centers()
self.assertArrayAlmostEqual(centers[0], [1.00, 1.01, 1.00], places=1)
self.assertArrayAlmostEqual(centers[1], [1.01, 1.00, 9.01], places=1)
self.assertArrayAlmostEqual(centers[2], [3.01, 2.01, 5.00], places=1)
self.assertArrayAlmostEqual(centers[3], [4.99, 8.00, 4.99], places=1)
self.assertArrayAlmostEqual(centers[4], [8.02, 2.00, 7.01], places=1)
doc = kmeans.pfaDocument("Cluster",
["one", "two", "three", "four", "five"],
preprocess=trans.new(AvroArray(AvroDouble()),
x="input[0]", y="input[1]", z="input[2]"))
# look(doc, maxDepth=10)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][0]["center"], [1.00, 1.01, 1.00], places=2)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][1]["center"], [1.01, 1.00, 9.01], places=2)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][2]["center"], [3.01, 2.01, 5.00], places=2)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][3]["center"], [4.99, 8.00, 4.99], places=2)
self.assertArrayAlmostEqual(doc["cells"]["clusters"]["init"][4]["center"], [8.02, 2.00, 7.01], places=2)
engine, = PFAEngine.fromJson(doc)
self.assertEqual(engine.action([1.00 * 10, 1.01 * 20, 1.00 * 30]), "one")
self.assertEqual(engine.action([1.01 * 10, 1.00 * 20, 9.01 * 30]), "two")
self.assertEqual(engine.action([3.01 * 10, 2.01 * 20, 5.00 * 30]), "three")
self.assertEqual(engine.action([4.99 * 10, 8.00 * 20, 4.99 * 30]), "four")
self.assertEqual(engine.action([8.02 * 10, 2.00 * 20, 7.01 * 30]), "five")
示例11: testCartMustBuildNumericalNumerical
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def testCartMustBuildNumericalNumerical(self):
random.seed(12345)
numpy.seterr(divide="ignore", invalid="ignore")
dataset = Dataset.fromIterable(((x, y, z) for (x, y, z, a, b, c) in TestProducerCart.data()), 100000, ("x", "y", "z"))
tree = TreeNode.fromWholeDataset(dataset, "z")
tree.splitMaxDepth(2)
doc = tree.pfaDocument({"type": "record", "name": "Datum", "fields": [{"name": "x", "type": "double"}, {"name": "y", "type": "double"}]}, "TreeNode")
# look(doc, maxDepth=8)
self.assertEqual(doc["cells"]["tree"]["init"]["field"], "x")
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["value"], 4.00, places=2)
self.assertEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["field"], "y")
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["value"], 6.00, places=2)
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["pass"]["double"], 5.00, places=2)
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["fail"]["double"], 8.02, places=2)
self.assertEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["field"], "y")
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["value"], 2.00, places=2)
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["pass"]["double"], 1.09, places=2)
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["fail"]["double"], 2.00, places=2)
engine, = PFAEngine.fromJson(doc)
self.assertAlmostEqual(engine.action({"x": 2.0, "y": 3.0}), 5.00, places=2)
self.assertAlmostEqual(engine.action({"x": 2.0, "y": 8.0}), 8.02, places=2)
self.assertAlmostEqual(engine.action({"x": 7.0, "y": 1.0}), 1.09, places=2)
self.assertAlmostEqual(engine.action({"x": 7.0, "y": 5.0}), 2.00, places=2)
doc = tree.pfaDocument(
{"type": "record", "name": "Datum", "fields": [{"name": "x", "type": "double"}, {"name": "y", "type": "double"}]},
"TreeNode",
nodeScores=True, datasetSize=True, predictandUnique=True, nTimesVariance=True, gain=True)
# look(doc, maxDepth=8)
engine, = PFAEngine.fromJson(doc)
示例12: testCartMustBuildNumericalCategorical
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def testCartMustBuildNumericalCategorical(self):
random.seed(12345)
numpy.seterr(divide="ignore", invalid="ignore")
dataset = Dataset.fromIterable(((x, y, c) for (x, y, z, a, b, c) in TestProducerCart.data()), 100000, ("x", "y", "c"))
tree = TreeNode.fromWholeDataset(dataset, "c")
tree.splitMaxDepth(2)
doc = tree.pfaDocument({"type": "record", "name": "Datum", "fields": [{"name": "x", "type": "double"}, {"name": "y", "type": "double"}]}, "TreeNode")
# look(doc, maxDepth=8)
self.assertEqual(doc["cells"]["tree"]["init"]["field"], "x")
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["value"], 4.00, places=2)
self.assertEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["field"], "y")
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["value"], 6.00, places=2)
self.assertEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["pass"]["string"], "C3")
self.assertEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["fail"]["string"], "C6")
self.assertEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["field"], "y")
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["value"], 2.00, places=2)
self.assertEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["pass"]["string"], "C0")
self.assertEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["fail"]["string"], "C0")
engine, = PFAEngine.fromJson(doc)
self.assertEqual(engine.action({"x": 2.0, "y": 3.0}), "C3")
self.assertEqual(engine.action({"x": 2.0, "y": 8.0}), "C6")
self.assertEqual(engine.action({"x": 7.0, "y": 1.0}), "C0")
self.assertEqual(engine.action({"x": 7.0, "y": 5.0}), "C0")
doc = tree.pfaDocument(
{"type": "record", "name": "Datum", "fields": [{"name": "x", "type": "double"}, {"name": "y", "type": "double"}]},
"TreeNode",
nodeScores=True, datasetSize=True, predictandDistribution=True, predictandUnique=True, entropy=True, gain=True)
# look(doc, maxDepth=8)
engine, = PFAEngine.fromJson(doc)
示例13: testCartMustBuildCategoricalNumerical
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def testCartMustBuildCategoricalNumerical(self):
random.seed(12345)
numpy.seterr(divide="ignore", invalid="ignore")
dataset = Dataset.fromIterable(((a, b, z) for (x, y, z, a, b, c) in TestProducerCart.data()), 100000, ("a", "b", "z"))
tree = TreeNode.fromWholeDataset(dataset, "z")
tree.splitMaxDepth(2)
doc = tree.pfaDocument({"type": "record", "name": "Datum", "fields": [{"name": "a", "type": "string"}, {"name": "b", "type": "string"}]}, "TreeNode")
# look(doc, maxDepth=8)
self.assertEqual(doc["cells"]["tree"]["init"]["field"], "a")
self.assertEqual(doc["cells"]["tree"]["init"]["value"], ["A0", "A1", "A2", "A3"])
self.assertEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["field"], "b")
self.assertEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["value"], ["B6", "B8"])
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["pass"]["double"], 8.02, places=2)
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["pass"]["TreeNode"]["fail"]["double"], 5.00, places=2)
self.assertEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["field"], "b")
self.assertEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["value"], ["B0"])
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["pass"]["double"], 1.09, places=2)
self.assertAlmostEqual(doc["cells"]["tree"]["init"]["fail"]["TreeNode"]["fail"]["double"], 2.00, places=2)
engine, = PFAEngine.fromJson(doc)
self.assertAlmostEqual(engine.action({"a": "A1", "b": "B6"}), 8.02, places=2)
self.assertAlmostEqual(engine.action({"a": "A1", "b": "B2"}), 5.00, places=2)
self.assertAlmostEqual(engine.action({"a": "A5", "b": "B0"}), 1.09, places=2)
self.assertAlmostEqual(engine.action({"a": "A5", "b": "B4"}), 2.00, places=2)
doc = tree.pfaDocument(
{"type": "record", "name": "Datum", "fields": [{"name": "a", "type": "string"}, {"name": "b", "type": "string"}]},
"TreeNode",
nodeScores=True, datasetSize=True, predictandUnique=True, nTimesVariance=True, gain=True)
# look(doc, maxDepth=8)
engine, = PFAEngine.fromJson(doc)
示例14: doKmeans
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def doKmeans(self):
numpy.seterr(divide="ignore", invalid="ignore")
# get a dataset for the k-means generator
dataset = []
for record in DataFileReader(open("test/prettypfa/exoplanets.avro", "r"), DatumReader()):
mag, dist, mass, radius = record.get("mag"), record.get("dist"), record.get("mass"), record.get("radius")
if mag is not None and dist is not None and mass is not None and radius is not None:
dataset.append([mag, dist, mass, radius])
# set up and run the k-means generator
TestClustering.kmeansResult = KMeans(len(self.clusterNames), numpy.array(dataset))
TestClustering.kmeansResult.optimize(whileall(moving(), maxIterations(1000)))
示例15: _calc_triangle_angles
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import seterr [as 别名]
def _calc_triangle_angles(p, eps=1e-5):
p1 = p[:, 0]
p2 = p[:, 1]
p3 = p[:, 2]
e1 = np.linalg.norm(p2 - p1, axis=1)
e2 = np.linalg.norm(p3 - p1, axis=1)
e3 = np.linalg.norm(p3 - p2, axis=1)
# Law Of Cossines
state = np.geterr()['invalid']
np.seterr(invalid='ignore')
a = np.zeros((p.shape[0], 3))
v = (e1 > eps) * (e2 > eps)
a[v, 0] = np.arccos((e2[v] ** 2 + e1[v] ** 2 - e3[v] ** 2) / (2 * e1[v] * e2[v]))
a[~v, 0] = 0
v = (e1 > eps) * (e3 > eps)
a[v, 1] = np.arccos((e1[v] ** 2 + e3[v] ** 2 - e2[v] ** 2) / (2 * e1[v] * e3[v]))
a[~v, 1] = 0
v = (e2 > eps) * (e3 > eps)
a[v, 2] = np.arccos((e2[v] ** 2 + e3[v] ** 2 - e1[v] ** 2) / (2 * e2[v] * e3[v]))
a[~v, 2] = 0
np.seterr(invalid=state)
a[np.isnan(a)] = np.pi
return a