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


Python numpy.nansum方法代码示例

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


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

示例1: test_emg_eventrelated

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_emg_eventrelated():

    emg = nk.emg_simulate(duration=20, sampling_rate=1000, burst_number=3)
    emg_signals, info = nk.emg_process(emg, sampling_rate=1000)
    epochs = nk.epochs_create(
        emg_signals, events=[3000, 6000, 9000], sampling_rate=1000, epochs_start=-0.1, epochs_end=1.9
    )
    emg_eventrelated = nk.emg_eventrelated(epochs)

    # Test amplitude features
    no_activation = np.where(emg_eventrelated["EMG_Activation"] == 0)[0][0]
    assert int(pd.DataFrame(emg_eventrelated.values[no_activation]).isna().sum()) == 4

    assert np.alltrue(
        np.nansum(np.array(emg_eventrelated["EMG_Amplitude_Mean"]))
        < np.nansum(np.array(emg_eventrelated["EMG_Amplitude_Max"]))
    )

    assert len(emg_eventrelated["Label"]) == 3 
开发者ID:neuropsychology,项目名称:NeuroKit,代码行数:21,代码来源:tests_emg.py

示例2: test_callable_metric

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_callable_metric():

    # Define callable metric that returns the l1 norm:
    def custom_callable(x, y, missing_values="NaN", squared=False):
        x = np.ma.array(x, mask=np.isnan(x))
        y = np.ma.array(y, mask=np.isnan(y))
        dist = np.nansum(np.abs(x-y))
        return dist

    X = np.array([
        [4, 3, 3, np.nan],
        [6, 9, 6, 9],
        [4, 8, 6, 9],
        [np.nan, 9, 11, 10.]
    ])

    X_imputed = np.array([
        [4, 3, 3, 9],
        [6, 9, 6, 9],
        [4, 8, 6, 9],
        [5, 9, 11, 10.]
    ])

    imputer = KNNImputer(n_neighbors=2, metric=custom_callable)
    assert_array_equal(imputer.fit_transform(X), X_imputed) 
开发者ID:epsilon-machine,项目名称:missingpy,代码行数:27,代码来源:test_knnimpute.py

示例3: test_sum_inf

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_sum_inf(self):
        s = Series(np.random.randn(10))
        s2 = s.copy()

        s[5:8] = np.inf
        s2[5:8] = np.nan

        assert np.isinf(s.sum())

        arr = np.random.randn(100, 100).astype('f4')
        arr[:, 2] = np.inf

        with pd.option_context("mode.use_inf_as_na", True):
            assert_almost_equal(s.sum(), s2.sum())

        res = nanops.nansum(arr, axis=1)
        assert np.isinf(res).all() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_analytics.py

示例4: _dominant_set_dense

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def _dominant_set_dense(s, k, is_thresh=False, norm=False, copy=True):
    """Compute dominant set for a dense matrix."""

    if is_thresh:
        s = s.copy() if copy else s
        s[s <= k] = 0

    else:  # keep top k
        nr, nc = s.shape
        idx = np.argpartition(s, nc - k, axis=1)
        row = np.arange(nr)[:, None]
        if copy:
            col = idx[:, -k:]  # idx largest
            data = s[row, col]
            s = np.zeros_like(s)
            s[row, col] = data
        else:
            col = idx[:, :-k]  # idx smallest
            s[row, col] = 0

    if norm:
        s /= np.nansum(s, axis=1, keepdims=True)

    return s 
开发者ID:MICA-MNI,项目名称:BrainSpace,代码行数:26,代码来源:utils.py

示例5: __call__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def __call__(self, x, y=None):
        (d,ii) = self.nearest(x, y)
        n = self.spatial_hash.n
        bd = (ii == n)
        ii[bd] = 0
        carea = np.reshape(self.surface_area[ii.flatten()], ii.shape)
        carea[bd] = np.nan
        d[bd] = np.nan
        if len(d.shape) == 1:
            varea = np.pi * np.nanmax(d)**2
            carea = np.nansum(carea)
        else:
            varea = np.pi * np.nanmax(d, axis=1)**2
            carea = np.nansum(carea, axis=1)
        return carea / varea 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:17,代码来源:cmag.py

示例6: get_class_center

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def get_class_center(Xs,Ys,Xt,dist):
	
    source_class_center = np.array([])
    Dct = np.array([])
    for i in np.unique(Ys):
        sel_mask = Ys == i
        X_i = Xs[sel_mask.flatten()]
        mean_i = np.mean(X_i, axis=0)
        if len(source_class_center) == 0:
            source_class_center = mean_i.reshape(-1, 1)
        else:
            source_class_center = np.hstack((source_class_center, mean_i.reshape(-1, 1)))
		
        if dist == "ma":
            Dct_c = get_ma_dist(Xt, X_i)
        elif dist == "euclidean":
            Dct_c = np.sqrt(np.nansum((mean_i - Xt)**2, axis=1))
        elif dist == "sqeuc":
            Dct_c = np.nansum((mean_i - Xt)**2, axis=1)
        elif dist == "cosine":
            Dct_c = get_cosine_dist(Xt, mean_i)
        elif dist == "rbf":
            Dct_c = np.nansum((mean_i - Xt)**2, axis=1)
            Dct_c = np.exp(- Dct_c / 1);
        
        if len(Dct) == 0:
            Dct = Dct_c.reshape(-1, 1)
        else:
            Dct = np.hstack((Dct, Dct_c.reshape(-1, 1)))
    
    return source_class_center, Dct 
开发者ID:jindongwang,项目名称:transferlearning,代码行数:33,代码来源:EasyTL.py

示例7: test_not_none

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_not_none(self):
        mech = nansum
        self.assertIsNotNone(mech) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:5,代码来源:test_nansum.py

示例8: test_no_params

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_no_params(self):
        a = np.array([1, 2, 3])
        with self.assertWarns(PrivacyLeakWarning):
            res = nansum(a)
        self.assertIsNotNone(res) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:7,代码来源:test_nansum.py

示例9: test_no_bounds

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_no_bounds(self):
        a = np.array([1, 2, 3])
        with self.assertWarns(PrivacyLeakWarning):
            res = nansum(a, epsilon=1)
        self.assertIsNotNone(res) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:7,代码来源:test_nansum.py

示例10: test_mis_ordered_bounds

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_mis_ordered_bounds(self):
        a = np.array([1, 2, 3])
        with self.assertRaises(ValueError):
            nansum(a, epsilon=1, bounds=(1, 0)) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:6,代码来源:test_nansum.py

示例11: test_missing_bounds

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_missing_bounds(self):
        a = np.array([1, 2, 3])
        with self.assertWarns(PrivacyLeakWarning):
            res = nansum(a, epsilon=1, bounds=None)
        self.assertIsNotNone(res) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:7,代码来源:test_nansum.py

示例12: test_inf_epsilon

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_inf_epsilon(self):
        a = np.random.random(1000)
        res = float(np.nansum(a))
        res_dp = nansum(a, epsilon=float("inf"), bounds=(0, 1))

        self.assertAlmostEqual(res, res_dp) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:8,代码来源:test_nansum.py

示例13: test_large_epsilon

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_large_epsilon(self):
        a = np.random.random(1000)
        res = float(np.nansum(a))
        res_dp = nansum(a, epsilon=1, bounds=(0, 1))

        self.assertAlmostEqual(res, res_dp, delta=0.01 * res) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:8,代码来源:test_nansum.py

示例14: test_axis

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_axis(self):
        a = np.random.random((1000, 5))
        res_dp = nansum(a, epsilon=1, axis=0, bounds=(0, 1))
        self.assertEqual(res_dp.shape, (5,)) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:6,代码来源:test_nansum.py

示例15: test_clipped_output

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_clipped_output(self):
        a = np.random.random((10,))

        for i in range(100):
            self.assertTrue(0 <= nansum(a, epsilon=1e-5, bounds=(0, 1)) <= 10) 
开发者ID:IBM,项目名称:differential-privacy-library,代码行数:7,代码来源:test_nansum.py


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