當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。