本文整理汇总了Python中numpy.ma.filled方法的典型用法代码示例。如果您正苦于以下问题:Python ma.filled方法的具体用法?Python ma.filled怎么用?Python ma.filled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.ma
的用法示例。
在下文中一共展示了ma.filled方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fillValuesToNan
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def fillValuesToNan(masked_array):
""" Replaces the fill_values of the masked array by NaNs
If the array is None or it does not contain floating point values, it cannot contain NaNs.
In that case the original array is returned.
"""
if masked_array is not None and masked_array.dtype.kind == 'f':
check_class(masked_array, ma.masked_array)
logger.debug("Replacing fill_values by NaNs")
masked_array[:] = ma.filled(masked_array, np.nan)
masked_array.set_fill_value(np.nan)
else:
return masked_array
#TODO: does recordMask help here?
# https://docs.scipy.org/doc/numpy/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray.recordmask
示例2: fill_values_to_nan
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def fill_values_to_nan(masked_array):
""" Replaces the fill_values of the masked array by NaNs
If the array is None or it does not contain floating point values, it cannot contain NaNs.
In that case the original array is returned.
"""
if masked_array is not None and masked_array.dtype.kind == 'f':
check_class(masked_array, ma.masked_array)
logger.debug("Replacing fill_values by NaNs")
masked_array[:] = ma.filled(masked_array, np.nan)
masked_array.set_fill_value(np.nan)
else:
return masked_array
# Needed because boolean QSettings in Pyside are converted incorrect the second
# time in Windows (and Linux?) because of a bug in Qt. See:
# https://www.mail-archive.com/pyside@lists.pyside.org/msg00230.html
示例3: f_value_wilks_lambda
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def f_value_wilks_lambda(ER, EF, dfnum, dfden, a, b):
"""Calculation of Wilks lambda F-statistic for multivariate data, per
Maxwell & Delaney p.657.
"""
ER = ma.array(ER, copy=False, ndmin=2)
EF = ma.array(EF, copy=False, ndmin=2)
if ma.getmask(ER).any() or ma.getmask(EF).any():
raise NotImplementedError("Not implemented when the inputs "
"have missing data")
lmbda = np.linalg.det(EF) / np.linalg.det(ER)
q = ma.sqrt(((a-1)**2*(b-1)**2 - 2) / ((a-1)**2 + (b-1)**2 - 5))
q = ma.filled(q, 1)
n_um = (1 - lmbda**(1.0/q))*(a-1)*(b-1)
d_en = lmbda**(1.0/q) / (n_um*q - 0.5*(a-1)*(b-1) + 1)
return n_um / d_en
示例4: smooth_median
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def smooth_median(self, iterations=1, width=1):
"""Smooth a surface using a median filter.
.. versionadded:: 2.1.0
"""
mask = ma.getmaskarray(self.values)
tmpv = ma.filled(self.values, fill_value=np.nan)
for _itr in range(iterations):
tmpv = scipy.ndimage.median_filter(tmpv, width)
tmpv = ma.masked_invalid(tmpv)
# seems that false areas of invalids (masked) may be made; combat that:
self.values = tmpv
self.fill()
self.values = ma.array(self.values, mask=mask)
示例5: _fix_output
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def _fix_output(output, usemask=True, asrecarray=False):
"""
Private function: return a recarray, a ndarray, a MaskedArray
or a MaskedRecords depending on the input parameters
"""
if not isinstance(output, MaskedArray):
usemask = False
if usemask:
if asrecarray:
output = output.view(MaskedRecords)
else:
output = ma.filled(output)
if asrecarray:
output = output.view(recarray)
return output
示例6: assign_fields_by_name
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def assign_fields_by_name(dst, src, zero_unassigned=True):
"""
Assigns values from one structured array to another by field name.
Normally in numpy >= 1.14, assignment of one structured array to another
copies fields "by position", meaning that the first field from the src is
copied to the first field of the dst, and so on, regardless of field name.
This function instead copies "by field name", such that fields in the dst
are assigned from the identically named field in the src. This applies
recursively for nested structures. This is how structure assignment worked
in numpy >= 1.6 to <= 1.13.
Parameters
----------
dst : ndarray
src : ndarray
The source and destination arrays during assignment.
zero_unassigned : bool, optional
If True, fields in the dst for which there was no matching
field in the src are filled with the value 0 (zero). This
was the behavior of numpy <= 1.13. If False, those fields
are not modified.
"""
if dst.dtype.names is None:
dst[...] = src
return
for name in dst.dtype.names:
if name not in src.dtype.names:
if zero_unassigned:
dst[name] = 0
else:
assign_fields_by_name(dst[name], src[name],
zero_unassigned)
示例7: argstoarray
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def argstoarray(*args):
"""
Constructs a 2D array from a group of sequences.
Sequences are filled with missing values to match the length of the longest
sequence.
Parameters
----------
args : sequences
Group of sequences.
Returns
-------
argstoarray : MaskedArray
A ( `m` x `n` ) masked array, where `m` is the number of arguments and
`n` the length of the longest argument.
Notes
-----
`numpy.ma.row_stack` has identical behavior, but is called with a sequence
of sequences.
"""
if len(args) == 1 and not isinstance(args[0], ndarray):
output = ma.asarray(args[0])
if output.ndim != 2:
raise ValueError("The input should be 2D")
else:
n = len(args)
m = max([len(k) for k in args])
output = ma.array(np.empty((n,m), dtype=float), mask=True)
for (k,v) in enumerate(args):
output[k,:len(v)] = v
output[np.logical_not(np.isfinite(output._data))] = masked
return output
示例8: msign
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def msign(x):
"""Returns the sign of x, or 0 if x is masked."""
return ma.filled(np.sign(x), 0)
示例9: argstoarray
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def argstoarray(*args):
"""
Constructs a 2D array from a group of sequences.
Sequences are filled with missing values to match the length of the longest
sequence.
Parameters
----------
args : sequences
Group of sequences.
Returns
-------
argstoarray : MaskedArray
A ( `m` x `n` ) masked array, where `m` is the number of arguments and
`n` the length of the longest argument.
Notes
-----
numpy.ma.row_stack has identical behavior, but is called with a sequence of
sequences.
"""
if len(args) == 1 and not isinstance(args[0], ndarray):
output = ma.asarray(args[0])
if output.ndim != 2:
raise ValueError("The input should be 2D")
else:
n = len(args)
m = max([len(k) for k in args])
output = ma.array(np.empty((n,m), dtype=float), mask=True)
for (k,v) in enumerate(args):
output[k,:len(v)] = v
output[np.logical_not(np.isfinite(output._data))] = masked
return output
#####--------------------------------------------------------------------------
#---- --- Ranking ---
#####--------------------------------------------------------------------------
示例10: ttest_rel
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def ttest_rel(a,b,axis=None):
a, b, axis = _chk2_asarray(a, b, axis)
if len(a) != len(b):
raise ValueError('unequal length arrays')
(x1, x2) = (a.mean(axis), b.mean(axis))
(v1, v2) = (a.var(axis=axis, ddof=1), b.var(axis=axis, ddof=1))
n = a.count(axis)
df = (n-1.0)
d = (a-b).astype('d')
denom = ma.sqrt((n*ma.add.reduce(d*d,axis) - ma.add.reduce(d,axis)**2) / df)
# zerodivproblem = denom == 0
t = ma.add.reduce(d, axis) / denom
t = ma.filled(t, 1)
probs = betai(0.5*df,0.5,df/(df+t*t)).reshape(t.shape).squeeze()
return t, probs
示例11: threshold
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def threshold(a, threshmin=None, threshmax=None, newval=0):
"""
Clip array to a given value.
Similar to numpy.clip(), except that values less than `threshmin` or
greater than `threshmax` are replaced by `newval`, instead of by
`threshmin` and `threshmax` respectively.
Parameters
----------
a : ndarray
Input data
threshmin : {None, float}, optional
Lower threshold. If None, set to the minimum value.
threshmax : {None, float}, optional
Upper threshold. If None, set to the maximum value.
newval : {0, float}, optional
Value outside the thresholds.
Returns
-------
threshold : ndarray
Returns `a`, with values less then `threshmin` and values greater
`threshmax` replaced with `newval`.
"""
a = ma.array(a, copy=True)
mask = np.zeros(a.shape, dtype=bool)
if threshmin is not None:
mask |= (a < threshmin).filled(False)
if threshmax is not None:
mask |= (a > threshmax).filled(False)
a[mask] = newval
return a
示例12: trima
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def trima(a, limits=None, inclusive=(True,True)):
"""Trims an array by masking the data outside some given limits.
Returns a masked version of the input array.
Parameters
----------
a : sequence
Input array.
limits : {None, tuple}, optional
Tuple of (lower limit, upper limit) in absolute values.
Values of the input array lower (greater) than the lower (upper) limit
will be masked. A limit is None indicates an open interval.
inclusive : {(True,True) tuple}, optional
Tuple of (lower flag, upper flag), indicating whether values exactly
equal to the lower (upper) limit are allowed.
"""
a = ma.asarray(a)
a.unshare_mask()
if limits is None:
return a
(lower_lim, upper_lim) = limits
(lower_in, upper_in) = inclusive
condition = False
if lower_lim is not None:
if lower_in:
condition |= (a < lower_lim)
else:
condition |= (a <= lower_lim)
if upper_lim is not None:
if upper_in:
condition |= (a > upper_lim)
else:
condition |= (a >= upper_lim)
a[condition.filled(True)] = masked
return a
示例13: f_value_wilks_lambda
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import filled [as 别名]
def f_value_wilks_lambda(ER, EF, dfnum, dfden, a, b):
"""Calculation of Wilks lambda F-statistic for multivarite data, per
Maxwell & Delaney p.657.
"""
ER = ma.array(ER, copy=False, ndmin=2)
EF = ma.array(EF, copy=False, ndmin=2)
if ma.getmask(ER).any() or ma.getmask(EF).any():
raise NotImplementedError("Not implemented when the inputs "
"have missing data")
lmbda = np.linalg.det(EF) / np.linalg.det(ER)
q = ma.sqrt(((a-1)**2*(b-1)**2 - 2) / ((a-1)**2 + (b-1)**2 - 5))
q = ma.filled(q, 1)
n_um = (1 - lmbda**(1.0/q))*(a-1)*(b-1)
d_en = lmbda**(1.0/q) / (n_um*q - 0.5*(a-1)*(b-1) + 1)
return n_um / d_en