本文整理汇总了Python中numpy.nanstd方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.nanstd方法的具体用法?Python numpy.nanstd怎么用?Python numpy.nanstd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.nanstd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dtype_from_dtype
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def test_dtype_from_dtype(self):
mat = np.eye(3)
codes = 'efdgFDG'
for nf, rf in zip(self.nanfuncs, self.stdfuncs):
for c in codes:
with suppress_warnings() as sup:
if nf in {np.nanstd, np.nanvar} and c in 'FDG':
# Giving the warning is a small bug, see gh-8000
sup.filter(np.ComplexWarning)
tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type
res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type
assert_(res is tgt)
# scalar case
tgt = rf(mat, dtype=np.dtype(c), axis=None).dtype.type
res = nf(mat, dtype=np.dtype(c), axis=None).dtype.type
assert_(res is tgt)
示例2: test_dtype_from_char
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def test_dtype_from_char(self):
mat = np.eye(3)
codes = 'efdgFDG'
for nf, rf in zip(self.nanfuncs, self.stdfuncs):
for c in codes:
with suppress_warnings() as sup:
if nf in {np.nanstd, np.nanvar} and c in 'FDG':
# Giving the warning is a small bug, see gh-8000
sup.filter(np.ComplexWarning)
tgt = rf(mat, dtype=c, axis=1).dtype.type
res = nf(mat, dtype=c, axis=1).dtype.type
assert_(res is tgt)
# scalar case
tgt = rf(mat, dtype=c, axis=None).dtype.type
res = nf(mat, dtype=c, axis=None).dtype.type
assert_(res is tgt)
示例3: test_ddof_too_big
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def test_ddof_too_big(self):
nanfuncs = [np.nanvar, np.nanstd]
stdfuncs = [np.var, np.std]
dsize = [len(d) for d in _rdat]
for nf, rf in zip(nanfuncs, stdfuncs):
for ddof in range(5):
with suppress_warnings() as sup:
sup.record(RuntimeWarning)
sup.filter(np.ComplexWarning)
tgt = [ddof >= d for d in dsize]
res = nf(_ndat, axis=1, ddof=ddof)
assert_equal(np.isnan(res), tgt)
if any(tgt):
assert_(len(sup.log) == 1)
else:
assert_(len(sup.log) == 0)
示例4: test_ddof_too_big
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def test_ddof_too_big(self):
nanfuncs = [np.nanvar, np.nanstd]
stdfuncs = [np.var, np.std]
dsize = [len(d) for d in _rdat]
for nf, rf in zip(nanfuncs, stdfuncs):
for ddof in range(5):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
tgt = [ddof >= d for d in dsize]
res = nf(_ndat, axis=1, ddof=ddof)
assert_equal(np.isnan(res), tgt)
if any(tgt):
assert_(len(w) == 1)
assert_(issubclass(w[0].category, RuntimeWarning))
else:
assert_(len(w) == 0)
示例5: compute_mean_metrics
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def compute_mean_metrics(json_folder, compute_averages=True):
files = glob.glob(os.path.join(json_folder, "*.json"))
sdr_inst_list = None
for path in files:
#print(path)
with open(path, "r") as f:
js = json.load(f)
if sdr_inst_list is None:
sdr_inst_list = [list() for _ in range(len(js["targets"]))]
for i in range(len(js["targets"])):
sdr_inst_list[i].extend([np.float(f['metrics']["SDR"]) for f in js["targets"][i]["frames"]])
#return np.array(sdr_acc), np.array(sdr_voc)
sdr_inst_list = [np.array(sdr) for sdr in sdr_inst_list]
if compute_averages:
return [(np.nanmedian(sdr), np.nanmedian(np.abs(sdr - np.nanmedian(sdr))), np.nanmean(sdr), np.nanstd(sdr)) for sdr in sdr_inst_list]
else:
return sdr_inst_list
示例6: _compute_scores_general
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def _compute_scores_general(df_experiments, df_expt_robust):
# parse specific metrics
scores = {
'Average-Robustness': np.mean(df_experiments[ImRegBenchmark.COL_ROBUSTNESS]),
'STD-Robustness': np.std(df_experiments[ImRegBenchmark.COL_ROBUSTNESS]),
'Median-Robustness': np.median(df_experiments[ImRegBenchmark.COL_ROBUSTNESS]),
'Average-Rank-Median-rTRE': np.nan,
'Average-Rank-Max-rTRE': np.nan,
}
# parse Mean & median specific measures
for name, col in [('Median-rTRE', 'rTRE Median'),
('Max-rTRE', 'rTRE Max'),
('Average-rTRE', 'rTRE Mean'),
('Norm-Time', COL_NORM_TIME)]:
for df, sufix in [(df_experiments, ''), (df_expt_robust, '-Robust')]:
scores['Average-' + name + sufix] = np.nanmean(df[col])
scores['STD-' + name + sufix] = np.nanstd(df[col])
scores['Median-' + name + sufix] = np.median(df[col])
return scores
示例7: nanstd
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def nanstd(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
"""Returns the standard deviation along an axis ignoring NaN values.
Args:
a (cupy.ndarray): Array to compute standard deviation.
axis (int): Along which axis to compute standard deviation. The
flattened array is used by default.
dtype: Data type specifier.
out (cupy.ndarray): Output array.
keepdims (bool): If ``True``, the axis is remained as an axis of
size one.
Returns:
cupy.ndarray: The standard deviation of the input array along the axis.
.. seealso:: :func:`numpy.nanstd`
"""
if a.dtype.kind in 'biu':
return a.std(axis=axis, dtype=dtype, out=out, ddof=ddof,
keepdims=keepdims)
# TODO(okuta): check type
return _statistics._nanstd(
a, axis=axis, dtype=dtype, out=out, ddof=ddof, keepdims=keepdims)
示例8: calculate_surface_statistics
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def calculate_surface_statistics(
realdf, ensemble, surfacefile, surfacefolder
) -> io.BytesIO:
fns = [
os.path.join(real_path, surfacefolder, surfacefile)
for real_path in list(realdf[realdf["ENSEMBLE"] == ensemble]["RUNPATH"])
]
surfaces = get_surfaces(fns)
return io.BytesIO(
json.dumps(
{
"mean": surface_to_json(surfaces.apply(np.nanmean, axis=0)),
"maximum": surface_to_json(surfaces.apply(np.nanmax, axis=0)),
"minimum": surface_to_json(surfaces.apply(np.nanmin, axis=0)),
"p10": surface_to_json(surfaces.apply(np.nanpercentile, 10, axis=0)),
"p90": surface_to_json(surfaces.apply(np.nanpercentile, 90, axis=0)),
"stddev": surface_to_json(surfaces.apply(np.nanstd, axis=0)),
}
).encode()
)
示例9: calc_statistics
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def calc_statistics(df):
# Switched P10 and P90 due to convention in petroleum industry
def p10(x):
return np.nanpercentile(x, q=90)
def p90(x):
return np.nanpercentile(x, q=10)
stat_dfs = []
for ens, ens_df in df.groupby("ENSEMBLE"):
stat_dfs.append(
ens_df.drop(columns=["REAL", "ENSEMBLE"])
.groupby("DATE", as_index=False)
.agg([np.nanmean, np.nanstd, np.nanmin, np.nanmax, p10, p90])
.reset_index()
.assign(ENSEMBLE=ens)
)
return pd.concat(stat_dfs)
示例10: save_surface
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def save_surface(fns, statistic) -> io.BytesIO:
surfaces = xtgeo.Surfaces(fns)
if len(surfaces.surfaces) == 0:
surface = xtgeo.RegularSurface()
elif statistic == "Mean":
surface = surfaces.apply(np.nanmean, axis=0)
elif statistic == "StdDev":
surface = surfaces.apply(np.nanstd, axis=0)
elif statistic == "Min":
surface = surfaces.apply(np.nanmin, axis=0)
elif statistic == "Max":
surface = surfaces.apply(np.nanmax, axis=0)
elif statistic == "P10":
surface = surfaces.apply(np.nanpercentile, 10, axis=0)
elif statistic == "P90":
surface = surfaces.apply(np.nanpercentile, 90, axis=0)
else:
surface = xtgeo.RegularSurface()
return io.BytesIO(surface_to_json(surface).encode())
示例11: _ecg_rsa_p2t
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def _ecg_rsa_p2t(rsp_onsets, rpeaks, sampling_rate, continuous=False, ecg_period=None, rsp_peaks=None):
"""Peak-to-trough algorithm (P2T)"""
# Find all RSP cycles and the Rpeaks within
cycles_rri = []
for idx in range(len(rsp_onsets) - 1):
cycle_init = rsp_onsets[idx]
cycle_end = rsp_onsets[idx + 1]
cycles_rri.append(rpeaks[np.logical_and(rpeaks >= cycle_init, rpeaks < cycle_end)])
# Iterate over all cycles
rsa_values = np.full(len(cycles_rri), np.nan)
for i, cycle in enumerate(cycles_rri):
# Estimate of RSA during each breath
RRis = np.diff(cycle) / sampling_rate
if len(RRis) > 1:
rsa_values[i] = np.max(RRis) - np.min(RRis)
if continuous is False:
rsa = {"RSA_P2T_Mean": np.nanmean(rsa_values)}
rsa["RSA_P2T_Mean_log"] = np.log(rsa["RSA_P2T_Mean"]) # pylint: disable=E1111
rsa["RSA_P2T_SD"] = np.nanstd(rsa_values, ddof=1)
rsa["RSA_P2T_NoRSA"] = len(pd.Series(rsa_values).index[pd.Series(rsa_values).isnull()])
else:
rsa = signal_interpolate(
x_values=rsp_peaks[~np.isnan(rsa_values)],
y_values=rsa_values[~np.isnan(rsa_values)],
x_new=np.arange(len(ecg_period)),
)
return rsa
示例12: _rsp_rrv_time
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def _rsp_rrv_time(bbi):
diff_bbi = np.diff(bbi)
out = {} # Initialize empty dict
# Mean based
out["RMSSD"] = np.sqrt(np.mean(diff_bbi ** 2))
out["MeanBB"] = np.nanmean(bbi)
out["SDBB"] = np.nanstd(bbi, ddof=1)
out["SDSD"] = np.nanstd(diff_bbi, ddof=1)
out["CVBB"] = out["SDBB"] / out["MeanBB"]
out["CVSD"] = out["RMSSD"] / out["MeanBB"]
# Robust
out["MedianBB"] = np.nanmedian(bbi)
out["MadBB"] = mad(bbi)
out["MCVBB"] = out["MadBB"] / out["MedianBB"]
# # Extreme-based
# nn50 = np.sum(np.abs(diff_rri) > 50)
# nn20 = np.sum(np.abs(diff_rri) > 20)
# out["pNN50"] = nn50 / len(rri) * 100
# out["pNN20"] = nn20 / len(rri) * 100
#
# # Geometrical domain
# bar_y, bar_x = np.histogram(rri, bins=range(300, 2000, 8))
# bar_y, bar_x = np.histogram(rri, bins="auto")
# out["TINN"] = np.max(bar_x) - np.min(bar_x) # Triangular Interpolation of the NN Interval Histogram
# out["HTI"] = len(rri) / np.max(bar_y) # HRV Triangular Index
return out
示例13: _standardize
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def _standardize(data, robust=False, window=None, **kwargs):
# Compute standardized on whole data
if window is None:
if robust is False:
z = (data - np.nanmean(data, axis=0)) / np.nanstd(data, axis=0, ddof=1)
else:
z = (data - np.nanmedian(data, axis=0)) / mad(data)
# Rolling standardization on windows
else:
df = pd.DataFrame(data) # Force dataframe
if robust is False:
z = (df - df.rolling(window, min_periods=0, **kwargs).mean()) / df.rolling(
window, min_periods=0, **kwargs
).std(ddof=1)
else:
z = (df - df.rolling(window, min_periods=0, **kwargs).median()) / df.rolling(
window, min_periods=0, **kwargs
).apply(mad)
# Fill the created nans
z = z.fillna(method="bfill")
# Restore to vector or array
if z.shape[1] == 1:
z = z[0].values
else:
z = z.values
return z
示例14: return_std
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def return_std(self):
values_array = np.array(self.vals, dtype=np.float)
return np.nanstd(values_array)
示例15: test_nanfunctions_matrices_general
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanstd [as 别名]
def test_nanfunctions_matrices_general():
# Check that it works and that type and
# shape are preserved
# 2018-04-29: moved here from core.tests.test_nanfunctions
mat = np.matrix(np.eye(3))
for f in (np.nanargmin, np.nanargmax, np.nansum, np.nanprod,
np.nanmean, np.nanvar, np.nanstd):
res = f(mat, axis=0)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (1, 3))
res = f(mat, axis=1)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (3, 1))
res = f(mat)
assert_(np.isscalar(res))
for f in np.nancumsum, np.nancumprod:
res = f(mat, axis=0)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (3, 3))
res = f(mat, axis=1)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (3, 3))
res = f(mat)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (1, 3*3))