当前位置: 首页>>代码示例>>Python>>正文


Python numpy.logspace方法代码示例

本文整理汇总了Python中numpy.logspace方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.logspace方法的具体用法?Python numpy.logspace怎么用?Python numpy.logspace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.logspace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dist_sma

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_dist_sma(self):
        """
        Test that smas outside of the range have zero probability

        """

        for mod in self.allmods:
            if 'dist_sma' in mod.__dict__:
                with RedirectStreams(stdout=self.dev_null):
                    pp = mod(**self.spec)

                a = np.logspace(np.log10(pp.arange[0].to('AU').value/10.),np.log10(pp.arange[1].to('AU').value*10.),100)

                fa = pp.dist_sma(a)
                self.assertTrue(np.all(fa[a < pp.arange[0].to('AU').value] == 0),'dist_sma high bound failed for %s'%mod.__name__)
                self.assertTrue(np.all(fa[a > pp.arange[1].to('AU').value] == 0),'dist_sma low bound failed for %s'%mod.__name__)
                self.assertTrue(np.all(fa[(a >= pp.arange[0].to('AU').value) & (a <= pp.arange[1].to('AU').value)] >= 0.),'dist_sma generates negative densities within range for %s'%mod.__name__) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:19,代码来源:test_PlanetPopulation.py

示例2: test_dist_radius

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_dist_radius(self):
        """
        Test that radii outside of the range have zero probability

        """
        for mod in self.allmods:
            if 'dist_radius' in mod.__dict__:
                with RedirectStreams(stdout=self.dev_null):
                    pp = mod(**self.spec)

                Rp = np.logspace(np.log10(pp.Rprange[0].to('earthRad').value/10.),np.log10(pp.Rprange[1].to('earthRad').value*100.),100) 

                fr = pp.dist_radius(Rp)
                self.assertTrue(np.all(fr[Rp < pp.Rprange[0].to('earthRad').value] == 0),'dist_radius high bound failed for %s'%mod.__name__)
                self.assertTrue(np.all(fr[Rp > pp.Rprange[1].to('earthRad').value] == 0),'dist_radius high bound failed for %s'%mod.__name__)
                self.assertTrue(np.all(fr[(Rp >= pp.Rprange[0].to('earthRad').value) & (Rp <= pp.Rprange[1].to('earthRad').value)] > 0),'dist_radius generates zero probabilities within range for %s'%mod.__name__) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:18,代码来源:test_PlanetPopulation.py

示例3: test_dist_mass

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_dist_mass(self):
        """
        Test that masses outside of the range have zero probability

        """

        for mod in self.allmods:
            if 'dist_mass' in mod.__dict__:
                with RedirectStreams(stdout=self.dev_null):
                    pp = mod(**self.spec)

                Mp = np.logspace(np.log10(pp.Mprange[0].value/10.),np.log10(pp.Mprange[1].value*100.),100) 

                fr = pp.dist_mass(Mp)
                self.assertTrue(np.all(fr[Mp < pp.Mprange[0].value] == 0),'dist_mass high bound failed for %s'%mod.__name__)
                self.assertTrue(np.all(fr[Mp > pp.Mprange[1].value] == 0),'dist_mass high bound failed for %s'%mod.__name__)
                self.assertTrue(np.all(fr[(Mp >= pp.Mprange[0].value) & (Mp <= pp.Mprange[1].value)] > 0)) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:19,代码来源:test_PlanetPopulation.py

示例4: test_dist_sma_radius

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_dist_sma_radius(self):
        """
        Test that sma and radius values outside of the range have zero probability
        """
        
        for mod in self.allmods:
            if 'dist_sma_radius' in mod.__dict__:
                with RedirectStreams(stdout=self.dev_null):
                    pp = mod(**self.spec)
                
                a = np.logspace(np.log10(pp.arange[0].value/10.),np.log10(pp.arange[1].value*100),100)
                Rp = np.logspace(np.log10(pp.Rprange[0].value/10.),np.log10(pp.Rprange[1].value*100),100)
                
                aa, RR = np.meshgrid(a,Rp)
                
                fr = pp.dist_sma_radius(aa,RR)
                self.assertTrue(np.all(fr[aa < pp.arange[0].value] == 0),'dist_sma_radius low bound failed on sma for %s'%mod.__name__)
                self.assertTrue(np.all(fr[aa > pp.arange[1].value] == 0),'dist_sma_radius high bound failed on sma for %s'%mod.__name__)
                self.assertTrue(np.all(fr[RR < pp.Rprange[0].value] == 0),'dist_sma_radius low bound failed on radius for %s'%mod.__name__)
                self.assertTrue(np.all(fr[RR > pp.Rprange[1].value] == 0),'dist_sma_radius high bound failed on radius for %s'%mod.__name__)
                self.assertTrue(np.all(fr[(aa > pp.arange[0].value) & (aa < pp.arange[1].value) & (RR > pp.Rprange[0].value) & (RR < pp.Rprange[1].value)] > 0),'dist_sma_radius is improper pdf for %s'%mod.__name__) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:23,代码来源:test_PlanetPopulation.py

示例5: test_nocross

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_nocross(self):
        # what happens when no gain/phase crossover?
        s = TransferFunction([1, 0], [1])
        h1 = 1/(1+s)
        h2 = 3*(10+s)/(2+s)
        h3 = 0.01*(10-s)/(2+s)/(1+s)
        gm, pm, wm, wg, wp, ws = stability_margins(h1)
        assert_array_almost_equal(
            [gm, pm, wg, wp],
            [float('Inf'), float('Inf'), float('NaN'), float('NaN')]) 
        gm, pm, wm, wg, wp, ws = stability_margins(h2)
        self.assertEqual(pm, float('Inf'))
        gm, pm, wm, wg, wp, ws = stability_margins(h3)
        self.assertTrue(np.isnan(wp))
        omega = np.logspace(-2,2, 100)
        out1b = stability_margins(FRD(h1, omega))
        out2b = stability_margins(FRD(h2, omega))
        out3b = stability_margins(FRD(h3, omega)) 
开发者ID:python-control,项目名称:python-control,代码行数:20,代码来源:margin_test.py

示例6: test_feedback_args

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_feedback_args(self):
        # Added 25 May 2019 to cover missing exception handling in feedback()
        # If first argument is not LTI or convertable, generate an exception
        args = ([1], self.sys2)
        self.assertRaises(TypeError, ctrl.feedback, *args)

        # If second argument is not LTI or convertable, generate an exception
        args = (self.sys1, np.array([1]))
        self.assertRaises(TypeError, ctrl.feedback, *args)

        # Convert first argument to FRD, if needed
        h = TransferFunction([1], [1, 2, 2])
        omega = np.logspace(-1, 2, 10)
        frd = ctrl.FRD(h, omega)
        sys = ctrl.feedback(1, frd)
        self.assertTrue(isinstance(sys, ctrl.FRD)) 
开发者ID:python-control,项目名称:python-control,代码行数:18,代码来源:bdalg_test.py

示例7: testMIMOSmooth

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def testMIMOSmooth(self):
        sys = StateSpace([[-0.5, 0.0], [0.0, -1.0]],
                         [[1.0, 0.0], [0.0, 1.0]],
                         [[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]],
                         [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]])
        sys2 = np.matrix([[1, 0, 0], [0, 1, 0]]) * sys
        omega = np.logspace(-1, 2, 10)
        f1 = FRD(sys, omega, smooth=True)
        f2 = FRD(sys2, omega, smooth=True)
        np.testing.assert_array_almost_equal(
            (f1*f2).freqresp([0.1, 1.0, 10])[0],
            (sys*sys2).freqresp([0.1, 1.0, 10])[0])
        np.testing.assert_array_almost_equal(
            (f1*f2).freqresp([0.1, 1.0, 10])[1],
            (sys*sys2).freqresp([0.1, 1.0, 10])[1])
        np.testing.assert_array_almost_equal(
            (f1*f2).freqresp([0.1, 1.0, 10])[2],
            (sys*sys2).freqresp([0.1, 1.0, 10])[2]) 
开发者ID:python-control,项目名称:python-control,代码行数:20,代码来源:frd_test.py

示例8: test_size_mismatch

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_size_mismatch(self):
        sys1 = FRD(ct.rss(2, 2, 2), np.logspace(-1, 1, 10))

        # Different number of inputs
        sys2 = FRD(ct.rss(3, 1, 2), np.logspace(-1, 1, 10))
        self.assertRaises(ValueError, FRD.__add__, sys1, sys2)

        # Different number of outputs
        sys2 = FRD(ct.rss(3, 2, 1), np.logspace(-1, 1, 10))
        self.assertRaises(ValueError, FRD.__add__, sys1, sys2)

        # Inputs and outputs don't match
        self.assertRaises(ValueError, FRD.__mul__, sys2, sys1)

        # Feedback mismatch
        self.assertRaises(ValueError, FRD.feedback, sys2, sys1) 
开发者ID:python-control,项目名称:python-control,代码行数:18,代码来源:frd_test.py

示例9: test_evalfr_deprecated

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_evalfr_deprecated(self):
        sys_tf = ct.tf([1], [1, 2, 1])
        frd_tf = FRD(sys_tf, np.logspace(-1, 1, 3))

        # Deprecated version of the call (should generate warning)
        import warnings
        with warnings.catch_warnings():
            # Make warnings generate an exception
            warnings.simplefilter('error')

            # Make sure that we get a pending deprecation warning
            self.assertRaises(PendingDeprecationWarning, frd_tf.evalfr, 1.)

        # FRD.evalfr() is being deprecated
        import warnings
        with warnings.catch_warnings():
            # Make warnings generate an exception
            warnings.simplefilter('error')

            # Make sure that we get a pending deprecation warning
            self.assertRaises(PendingDeprecationWarning, frd_tf.evalfr, 1.) 
开发者ID:python-control,项目名称:python-control,代码行数:23,代码来源:frd_test.py

示例10: test_custom_bode_default

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_custom_bode_default(self):
        ct.config.defaults['bode.dB'] = True
        ct.config.defaults['bode.deg'] = True
        ct.config.defaults['bode.Hz'] = True

        # Generate a Bode plot
        plt.figure()
        omega = np.logspace(-3, 3, 100)
        ct.bode_plot(self.sys, omega, dB=True)
        mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data()
        np.testing.assert_almost_equal(mag_y[0], 20*log10(10), decimal=3)

        # Override defaults
        plt.figure()
        ct.bode_plot(self.sys, omega, Hz=True, deg=False, dB=True)
        mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data()
        phase_x, phase_y = (((plt.gcf().axes[1]).get_lines())[0]).get_data()
        np.testing.assert_almost_equal(mag_x[0], 0.001 / (2*pi), decimal=6)
        np.testing.assert_almost_equal(mag_y[0], 20*log10(10), decimal=3)
        np.testing.assert_almost_equal(phase_y[-1], -pi, decimal=2)

        ct.reset_defaults() 
开发者ID:python-control,项目名称:python-control,代码行数:24,代码来源:config_test.py

示例11: test_celer_path

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_celer_path(sparse_X, alphas, pb):
    """Test Lasso path convergence."""
    X, y = build_dataset(n_samples=30, n_features=50, sparse_X=sparse_X)
    if pb == "logreg":
        y = np.sign(y)
    n_samples = X.shape[0]
    if alphas is not None:
        alpha_max = np.max(np.abs(X.T.dot(y))) / n_samples
        n_alphas = 10
        alphas = alpha_max * np.logspace(0, -2, n_alphas)

    tol = 1e-6
    alphas, coefs, gaps, thetas, n_iters = celer_path(
        X, y, pb, alphas=alphas, tol=tol, return_thetas=True,
        verbose=1, return_n_iter=True)
    np.testing.assert_array_less(gaps, tol)
    # hack because array_less wants strict inequality
    np.testing.assert_array_less(0.99, n_iters) 
开发者ID:mathurinm,项目名称:celer,代码行数:20,代码来源:test_lasso.py

示例12: test_warm_start

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def test_warm_start():
    """Test Lasso path convergence."""
    X, y = build_dataset(
        n_samples=100, n_features=100, sparse_X=True)
    n_samples, n_features = X.shape
    alpha_max = np.max(np.abs(X.T.dot(y))) / n_samples
    n_alphas = 10
    alphas = alpha_max * np.logspace(0, -2, n_alphas)

    reg1 = Lasso(tol=1e-6, warm_start=True, p0=10)
    reg1.coef_ = np.zeros(n_features)

    for alpha in alphas:
        reg1.set_params(alpha=alpha)
        reg1.fit(X, y)
        # refitting with warm start should take less than 2 iters:
        reg1.fit(X, y)
        # hack because assert_array_less does strict comparison...
        np.testing.assert_array_less(reg1.n_iter_, 2.01) 
开发者ID:mathurinm,项目名称:celer,代码行数:21,代码来源:test_lasso.py

示例13: _define_line_spacing

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def _define_line_spacing(self, maximum_distance, spacing, as_log=False):
        """
        The user may wish to define the line spacing in either log or
        linear space
        """
        nvals = int(maximum_distance / spacing) + 1
        if as_log:
            spacings = np.logspace(-3., np.log10(maximum_distance), nvals)
            spacings[0] = 0.0
        else:
            spacings = np.linspace(0.0, maximum_distance, nvals)

        if spacings[-1] < (maximum_distance - 1.0E-7):
            spacings = np.hstack([spacings, maximum_distance])

        return spacings 
开发者ID:GEMScienceTools,项目名称:gmpe-smtk,代码行数:18,代码来源:configure.py

示例14: PlotEStarRStarTheoretical

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def PlotEStarRStarTheoretical():
    """
    This makes the theoretical E* vs R* plot. It prints to the current open figure.
    SMM Note: This would be better if it used a supploed figure. Can the default be get_clf()?

    MDH

    """
    # Calculate analytical relationship
    EStar = np.logspace(-1,3,1000)
    RStar = CalculateRStar(EStar)

    # Plot with open figure
    plt.plot(EStar,RStar,'k--')


#-------------------------------------------------------------------------------#
# PLOTTING FUNCTIONS
#-------------------------------------------------------------------------------#
# SMM: Checked and working 13/06/2018 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:22,代码来源:LSDMap_HillslopeMorphology.py

示例15: __init__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logspace [as 别名]
def __init__(self, base_estimator=LogisticRegression(penalty='l1'), lambda_name='C',
                 lambda_grid=np.logspace(-5, -2, 25), n_bootstrap_iterations=100,
                 sample_fraction=0.5, threshold=0.6, bootstrap_func=bootstrap_without_replacement,
                 bootstrap_threshold=None, verbose=0, n_jobs=1, pre_dispatch='2*n_jobs',
                 random_state=None):
        self.base_estimator = base_estimator
        self.lambda_name = lambda_name
        self.lambda_grid = lambda_grid
        self.n_bootstrap_iterations = n_bootstrap_iterations
        self.sample_fraction = sample_fraction
        self.threshold = threshold
        self.bootstrap_func = bootstrap_func
        self.bootstrap_threshold = bootstrap_threshold
        self.verbose = verbose
        self.n_jobs = n_jobs
        self.pre_dispatch = pre_dispatch
        self.random_state = random_state 
开发者ID:scikit-learn-contrib,项目名称:stability-selection,代码行数:19,代码来源:stability_selection.py


注:本文中的numpy.logspace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。