• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ma.arange函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.ma.arange函数的典型用法代码示例。如果您正苦于以下问题:Python arange函数的具体用法?Python arange怎么用?Python arange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_testPut2

    def test_testPut2(self):
        # Test of put
        d = arange(5)
        x = array(d, mask=[0, 0, 0, 0, 0])
        z = array([10, 40], mask=[1, 0])
        assert_(x[2] is not masked)
        assert_(x[3] is not masked)
        x[2:4] = z
        assert_(x[2] is masked)
        assert_(x[3] is not masked)
        assert_(eq(x, [0, 1, 10, 40, 4]))

        d = arange(5)
        x = array(d, mask=[0, 0, 0, 0, 0])
        y = x[2:4]
        z = array([10, 40], mask=[1, 0])
        assert_(x[2] is not masked)
        assert_(x[3] is not masked)
        y[:] = z
        assert_(y[0] is masked)
        assert_(y[1] is not masked)
        assert_(eq(y, [10, 40]))
        assert_(x[2] is masked)
        assert_(x[3] is not masked)
        assert_(eq(x, [0, 1, 10, 40, 4]))
开发者ID:numpy,项目名称:numpy,代码行数:25,代码来源:test_old_ma.py


示例2: test_testAverage2

    def test_testAverage2(self):
        # More tests of average.
        w1 = [0, 1, 1, 1, 1, 0]
        w2 = [[0, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 1]]
        x = arange(6)
        assert_(allclose(average(x, axis=0), 2.5))
        assert_(allclose(average(x, axis=0, weights=w1), 2.5))
        y = array([arange(6), 2.0 * arange(6)])
        assert_(allclose(average(y, None),
                                 np.add.reduce(np.arange(6)) * 3. / 12.))
        assert_(allclose(average(y, axis=0), np.arange(6) * 3. / 2.))
        assert_(allclose(average(y, axis=1),
                                 [average(x, axis=0), average(x, axis=0)*2.0]))
        assert_(allclose(average(y, None, weights=w2), 20. / 6.))
        assert_(allclose(average(y, axis=0, weights=w2),
                                 [0., 1., 2., 3., 4., 10.]))
        assert_(allclose(average(y, axis=1),
                                 [average(x, axis=0), average(x, axis=0)*2.0]))
        m1 = zeros(6)
        m2 = [0, 0, 1, 1, 0, 0]
        m3 = [[0, 0, 1, 1, 0, 0], [0, 1, 1, 1, 1, 0]]
        m4 = ones(6)
        m5 = [0, 1, 1, 1, 1, 1]
        assert_(allclose(average(masked_array(x, m1), axis=0), 2.5))
        assert_(allclose(average(masked_array(x, m2), axis=0), 2.5))
        assert_(average(masked_array(x, m4), axis=0) is masked)
        assert_equal(average(masked_array(x, m5), axis=0), 0.0)
        assert_equal(count(average(masked_array(x, m4), axis=0)), 0)
        z = masked_array(y, m3)
        assert_(allclose(average(z, None), 20. / 6.))
        assert_(allclose(average(z, axis=0),
                                 [0., 1., 99., 99., 4.0, 7.5]))
        assert_(allclose(average(z, axis=1), [2.5, 5.0]))
        assert_(allclose(average(z, axis=0, weights=w2),
                                 [0., 1., 99., 99., 4.0, 10.0]))

        a = arange(6)
        b = arange(6) * 3
        r1, w1 = average([[a, b], [b, a]], axis=1, returned=1)
        assert_equal(shape(r1), shape(w1))
        assert_equal(r1.shape, w1.shape)
        r2, w2 = average(ones((2, 2, 3)), axis=0, weights=[3, 1], returned=1)
        assert_equal(shape(w2), shape(r2))
        r2, w2 = average(ones((2, 2, 3)), returned=1)
        assert_equal(shape(w2), shape(r2))
        r2, w2 = average(ones((2, 2, 3)), weights=ones((2, 2, 3)), returned=1)
        assert_(shape(w2) == shape(r2))
        a2d = array([[1, 2], [0, 4]], float)
        a2dm = masked_array(a2d, [[0, 0], [1, 0]])
        a2da = average(a2d, axis=0)
        assert_(eq(a2da, [0.5, 3.0]))
        a2dma = average(a2dm, axis=0)
        assert_(eq(a2dma, [1.0, 3.0]))
        a2dma = average(a2dm, axis=None)
        assert_(eq(a2dma, 7. / 3.))
        a2dma = average(a2dm, axis=1)
        assert_(eq(a2dma, [1.5, 4.0]))
开发者ID:numpy,项目名称:numpy,代码行数:57,代码来源:test_old_ma.py


示例3: test_testMinMax2

 def test_testMinMax2(self):
     # Test of minimum, maximum.
     assert_(eq(minimum([1, 2, 3], [4, 0, 9]), [1, 0, 3]))
     assert_(eq(maximum([1, 2, 3], [4, 0, 9]), [4, 2, 9]))
     x = arange(5)
     y = arange(5) - 2
     x[3] = masked
     y[0] = masked
     assert_(eq(minimum(x, y), where(less(x, y), x, y)))
     assert_(eq(maximum(x, y), where(greater(x, y), x, y)))
     assert_(minimum.reduce(x) == 0)
     assert_(maximum.reduce(x) == 4)
开发者ID:numpy,项目名称:numpy,代码行数:12,代码来源:test_old_ma.py


示例4: grid_linefit

def grid_linefit(grid, timevals=None, timeslice=slice(None, None, None)):
    """A compressed spatiotemporal grid is provided. A line fit is performed 
    along the time axis for each spatial cell. Two grids are returned,
    each of which is 2d, with the same spatial shape as the input.
    The pixels of one grid contains the slope, the other contains the 
    r squared value of the line fit for that spatial cell.
    A vector of time values may be provided. If not supplied, one 
    will be generated."""
    if timevals == None:
        timevals = ma.arange(grid.shape[0])
    X = sm.add_constant(timevals, prepend=True)

    outshape = (grid.shape[1],)

    rsq_map = ma.zeros(outshape)
    slope_map = ma.zeros(outshape)

    for i in range(outshape[0]):
        if (i % 1000) == 0:
            print "%d of %d (%f)" % (i, outshape[0], (i * 100.0) / outshape[0])
        if (type(grid) == "numpy.ma.core.MaskedArray") and grid[0, :].mask[i]:
            rsq_map[i] = ma.masked
            slope_map[i] = ma.masked
        else:
            m, rsq = linefit(grid, i, X, timeslice)
            rsq_map[i] = rsq
            slope_map[i] = m

    return (slope_map, rsq_map)
开发者ID:bnordgren,项目名称:pylsce,代码行数:29,代码来源:trend.py


示例5: plotBestFit

def plotBestFit(weights):
    import matplotlib.pyplot as plt
    dataMat, labelMat = loadDataSet()
    dataArr = array(dataMat)
    n = shape(dataArr)[0]
    xcord1 = []
    ycord1 = []
    xcord2 = []
    ycord2 = []
    for i in range(n):
        if int(labelMat[i]) == 1:
            xcord1.append(dataArr[i, 1])
            ycord1.append(dataArr[i, 2])
        else:
            xcord2.append(dataArr[i, 1])
            ycord2.append(dataArr[i, 2])
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(xcord1, ycord1, s=30, c='red', marker='s')
    ax.scatter(xcord2, ycord2, s=30, c='green')
    x = arange(-3.0, 3.0, 0.1)
    y = (-weights[0] - weights[1] * x) / weights[2]
    ax.plot(x, y)
    plt.xlabel('X')
    plt.ylabel('Y')
    plt.show()
开发者ID:daihui,项目名称:machinelearning,代码行数:26,代码来源:logRegres.py


示例6: test_testMasked

 def test_testMasked(self):
     # Test of masked element
     xx = arange(6)
     xx[1] = masked
     self.assertTrue(str(masked) == '--')
     self.assertTrue(xx[1] is masked)
     self.assertEqual(filled(xx[1], 0), 0)
开发者ID:8ballbb,项目名称:ProjectRothar,代码行数:7,代码来源:test_old_ma.py


示例7: solve_equation

def solve_equation(k, m, x0, xk, n, h, t, w, x, solver, method_name, draw_flag):
    solver(k, m, x0, xk, n, h, t, w, x)
    xx = arange(x0, xk, 0.1)
    f_y = []
    for i in x:
        f_y.append(calculate_f_x_1(i, k, m))
    mean_square_error = calculate_mean_square_error(x, f_y, w)
    max_error = calculate_max_norm(x, f_y, w)
    mean_format = "{:.4f}"
    max_format = "{:.4f}"
    if mean_square_error < 0.0001:
        mean_format = "{:.3e}"
    elif mean_square_error > 100:
        mean_format = "{:.0f}"
    if max_error < 0.0001:
        max_format = "{:.3e}"
    elif max_error > 100:
        max_format = "{:.0f}"
    print(";".join((str(n), mean_format.format(mean_square_error), max_format.format(max_error))))
    if draw_flag:
        add_to_plot(xx, calculate_f_x_1(xx, k, m), "Given function")
        add_to_plot(x, w, method_name + " differential")
        file_name = method_name + "_" + str(n)
        title = (
            method_name
            + "  n = "
            + str(n)
            + "\n mean square error = "
            + mean_format.format(mean_square_error)
            + "\n max error = "
            + max_format.format(max_error)
        )
        draw_plot(title, file_name)
开发者ID:WiktorJ,项目名称:Computation-Methods,代码行数:33,代码来源:FirstOrderDifferentialSolver.py


示例8: test_testMasked

 def test_testMasked(self):
     # Test of masked element
     xx = arange(6)
     xx[1] = masked
     assert_(str(masked) == '--')
     assert_(xx[1] is masked)
     assert_equal(filled(xx[1], 0), 0)
开发者ID:numpy,项目名称:numpy,代码行数:7,代码来源:test_old_ma.py


示例9: brute_force

def brute_force(f, a, b, segments):
    x0 = a
    x1 = b
    dx = (x1 - x0) / segments

    fs = map(lambda _x: (_x, f(_x)), arange(x0, x1, dx))
    return min(fs, key=lambda xf: abs(xf[1]))
开发者ID:germtb,项目名称:Pysics,代码行数:7,代码来源:algorithms.py


示例10: test_pearsonr

    def test_pearsonr(self):
        # Tests some computations of Pearson's r
        x = ma.arange(10)
        with warnings.catch_warnings():
            # The tests in this context are edge cases, with perfect
            # correlation or anticorrelation, or totally masked data.
            # None of these should trigger a RuntimeWarning.
            warnings.simplefilter("error", RuntimeWarning)

            assert_almost_equal(mstats.pearsonr(x, x)[0], 1.0)
            assert_almost_equal(mstats.pearsonr(x, x[::-1])[0], -1.0)

            x = ma.array(x, mask=True)
            pr = mstats.pearsonr(x, x)
            assert_(pr[0] is masked)
            assert_(pr[1] is masked)

        x1 = ma.array([-1.0, 0.0, 1.0])
        y1 = ma.array([0, 0, 3])
        r, p = mstats.pearsonr(x1, y1)
        assert_almost_equal(r, np.sqrt(3)/2)
        assert_almost_equal(p, 1.0/3)

        # (x2, y2) have the same unmasked data as (x1, y1).
        mask = [False, False, False, True]
        x2 = ma.array([-1.0, 0.0, 1.0, 99.0], mask=mask)
        y2 = ma.array([0, 0, 3, -1], mask=mask)
        r, p = mstats.pearsonr(x2, y2)
        assert_almost_equal(r, np.sqrt(3)/2)
        assert_almost_equal(p, 1.0/3)
开发者ID:andycasey,项目名称:scipy,代码行数:30,代码来源:test_mstats_basic.py


示例11: test_masked_1d_single

 def test_masked_1d_single(self):
     data = ma.arange(11)
     data[3:7] = ma.masked
     actual = PERCENTILE.aggregate(data, axis=0, percent=50)
     expected = 7
     self.assertTupleEqual(actual.shape, ())
     self.assertEqual(actual, expected)
开发者ID:QuLogic,项目名称:iris,代码行数:7,代码来源:test_PERCENTILE.py


示例12: self_training

def self_training(X, y, X_unLabeled, clf, th):
    clf.fit(X=X, y=y)
    index_unlabeled = ma.arange(0, len(X_unLabeled), 1)
    y_unlabeled = np.zeros(len(X_unLabeled))
    train_is_failed = False

    while True:
        probs = clf.predict_proba(X=X_unLabeled[~ma.getmaskarray(index_unlabeled)])
        index_greater_equal = np.greater_equal([max(d) for d in probs], [th]*len(probs))
        index_labelable = index_unlabeled.data[~ma.getmaskarray(index_unlabeled)][index_greater_equal]

        if not len(index_labelable) > 0:
            if not len(index_unlabeled.data[ma.getmaskarray(index_unlabeled)]) > 0:
                train_is_failed = True
            break

        index_unlabeled[index_labelable] = ma.masked

        if index_unlabeled.all() is ma.masked:
            break

        y_unlabeled[index_labelable] = [np.argmax(p) for p in probs[index_greater_equal]]

        X_labelable = X_unLabeled[index_unlabeled.mask]
        y_labelable = y_unlabeled[index_unlabeled.mask]

        clf.fit(X=np.append(X, X_labelable, axis=0),
                y=np.append(y, y_labelable))

    if train_is_failed:
        y_unlabeled = []
    else:
        y_unlabeled = ma.array(data=y_unlabeled, mask=index_unlabeled.mask)

    return clf, y_unlabeled
开发者ID:TatsuyukiIju,项目名称:data_projection,代码行数:35,代码来源:test.py


示例13: test_scalar_mask

 def test_scalar_mask(self):
     # Testing the bug raised in https://github.com/SciTools/iris/pull/123#issuecomment-9309872
     # (the fix workaround for the np.append bug failed for scalar masks) 
     cube = tests.stock.realistic_4d_w_missing_data()
     cube.data = ma.arange(np.product(cube.shape), dtype=np.float32).reshape(cube.shape)
     cube.coord('grid_longitude').circular = True
     # There's no result to test, just make sure we don't cause an exception with the scalar mask.
     _ = iris.analysis.interpolate.linear(cube, [('grid_longitude', 0), ('grid_latitude', 0)])
开发者ID:Jozhogg,项目名称:iris,代码行数:8,代码来源:test_interpolation.py


示例14: test_multi

    def test_multi(self):
        for dtype in [np.int, np.float]:
            data = ma.arange(12, dtype=dtype)
            data[::2] = ma.masked
            self._check(data.reshape(3, 4))

            data = ma.arange(12, dtype=dtype)
            data[1::2] = ma.masked
            self._check(data.reshape(3, 4))

            data = ma.arange(12, dtype=dtype).reshape(3, 4)
            data[::2] = ma.masked
            self._check(data)

            data = ma.arange(12, dtype=dtype).reshape(3, 4)
            data[1::2] = ma.masked
            self._check(data)
开发者ID:QuLogic,项目名称:biggus,代码行数:17,代码来源:test_count.py


示例15: test_masked_1d_multi

 def test_masked_1d_multi(self):
     data = ma.arange(11)
     data[3:9] = ma.masked
     percent = np.array([25, 50, 75])
     actual = PERCENTILE.aggregate(data, axis=0, percent=percent)
     expected = [1, 2, 9]
     self.assertTupleEqual(actual.shape, percent.shape)
     self.assertArrayEqual(actual, expected)
开发者ID:QuLogic,项目名称:iris,代码行数:8,代码来源:test_PERCENTILE.py


示例16: test_trim

    def test_trim(self):
        a = ma.arange(10)
        assert_equal(mstats.trim(a), [0,1,2,3,4,5,6,7,8,9])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,(2,8)), [None,None,2,3,4,5,6,7,8,None])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,limits=(2,8),inclusive=(False,False)),
                     [None,None,None,3,4,5,6,7,None,None])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,limits=(0.1,0.2),relative=True),
                     [None,1,2,3,4,5,6,7,None,None])

        a = ma.arange(12)
        a[[0,-1]] = a[5] = masked
        assert_equal(mstats.trim(a,(2,8)),
                     [None,None,2,3,4,None,6,7,8,None,None,None])

        x = ma.arange(100).reshape(10,10)
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=None)
        assert_equal(trimx._mask.ravel(),[1]*10+[0]*70+[1]*20)
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=0)
        assert_equal(trimx._mask.ravel(),[1]*10+[0]*70+[1]*20)
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=-1)
        assert_equal(trimx._mask.T.ravel(),[1]*10+[0]*70+[1]*20)

        x = ma.arange(110).reshape(11,10)
        x[1] = masked
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=None)
        assert_equal(trimx._mask.ravel(),[1]*20+[0]*70+[1]*20)
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=0)
        assert_equal(trimx._mask.ravel(),[1]*20+[0]*70+[1]*20)
        trimx = mstats.trim(x.T,(0.1,0.2),relative=True,axis=-1)
        assert_equal(trimx.T._mask.ravel(),[1]*20+[0]*70+[1]*20)
开发者ID:bulli92,项目名称:scipy,代码行数:33,代码来源:test_mstats_basic.py


示例17: test_minmax

 def test_minmax(self):
     a = arange(1, 13).reshape(3, 4)
     amask = masked_where(a < 5, a)
     assert_equal(amask.max(), a.max())
     assert_equal(amask.min(), 5)
     assert_((amask.max(0) == a.max(0)).all())
     assert_((amask.min(0) == [5, 6, 7, 8]).all())
     assert_(amask.max(1)[0].mask)
     assert_(amask.min(1)[0].mask)
开发者ID:numpy,项目名称:numpy,代码行数:9,代码来源:test_old_ma.py


示例18: test_testPickle

 def test_testPickle(self):
     # Test of pickling
     x = arange(12)
     x[4:10:2] = masked
     x = x.reshape(4, 3)
     for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
         s = pickle.dumps(x, protocol=proto)
         y = pickle.loads(s)
         assert_(eq(x, y))
开发者ID:numpy,项目名称:numpy,代码行数:9,代码来源:test_old_ma.py


示例19: setUp

 def setUp(self):
     self.data = ma.arange(12).reshape(3, 4)
     self.data.mask = [[0, 0, 0, 1],
                       [0, 0, 1, 1],
                       [0, 1, 1, 1]]
     # --> fractions of masked-points in columns = [0, 1/3, 2/3, 1]
     self.array = as_lazy_data(self.data)
     self.axis = 0
     self.expected_masked = ma.mean(self.data, axis=self.axis)
开发者ID:SciTools,项目名称:iris,代码行数:9,代码来源:test_MEAN.py


示例20: test_flat

    def test_flat(self):
        for dtype in [np.int, np.float]:
            data = ma.arange(12, dtype=dtype)
            data[::2] = ma.masked
            self._check(data)

            data.mask = ma.nomask
            data[1::2] = ma.masked
            self._check(data)
开发者ID:QuLogic,项目名称:biggus,代码行数:9,代码来源:test_count.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ma.arctan2函数代码示例发布时间:2022-05-27
下一篇:
Python ma.apply_along_axis函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap