本文整理汇总了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
示例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)
示例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()
示例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
示例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
示例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
示例7: test_not_none
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nansum [as 别名]
def test_not_none(self):
mech = nansum
self.assertIsNotNone(mech)
示例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)
示例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)
示例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))
示例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)
示例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)
示例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)
示例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,))
示例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)