當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.seterr方法代碼示例

本文整理匯總了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') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_core.py

示例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] 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:_distn_infrastructure.py

示例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') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:18,代碼來源:test_core.py

示例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) 
開發者ID:lacava,項目名稱:few,代碼行數:20,代碼來源:evaluation.py

示例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 
開發者ID:NervanaSystems,項目名稱:ngraph-python,代碼行數:23,代碼來源:decorators.py

示例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) 
開發者ID:tensorflow,項目名稱:data-validation,代碼行數:19,代碼來源:basic_stats_generator_test.py

示例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 
開發者ID:allenai,項目名稱:comb_dist_direct_relex,代碼行數:22,代碼來源:test_multilabel_average_precision_metric.py

示例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') 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:test_core.py

示例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") 
開發者ID:modelop,項目名稱:hadrian,代碼行數:38,代碼來源:testKMeans.py

示例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") 
開發者ID:modelop,項目名稱:hadrian,代碼行數:42,代碼來源:testKMeans.py

示例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) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:36,代碼來源:testCart.py

示例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) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:36,代碼來源:testCart.py

示例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) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:36,代碼來源:testCart.py

示例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))) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:15,代碼來源:testClustering.py

示例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 
開發者ID:simnibs,項目名稱:simnibs,代碼行數:29,代碼來源:electrode_placement.py


注:本文中的numpy.seterr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。