本文整理汇总了Python中numpy.core.numeric.where方法的典型用法代码示例。如果您正苦于以下问题:Python numeric.where方法的具体用法?Python numeric.where怎么用?Python numeric.where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.core.numeric
的用法示例。
在下文中一共展示了numeric.where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: allequal
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def allequal (a, b, fill_value=1):
"""
True if all entries of a and b are equal, using
fill_value as a truth value where either or both are masked.
"""
m = mask_or(getmask(a), getmask(b))
if m is nomask:
x = filled(a)
y = filled(b)
d = umath.equal(x, y)
return fromnumeric.alltrue(fromnumeric.ravel(d))
elif fill_value:
x = filled(a)
y = filled(b)
d = umath.equal(x, y)
dm = array(d, mask=m, copy=0)
return fromnumeric.alltrue(fromnumeric.ravel(filled(dm, 1)))
else:
return 0
示例2: masked_values
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):
"""
masked_values(data, value, rtol=1.e-5, atol=1.e-8)
Create a masked array; mask is nomask if possible.
If copy==0, and otherwise possible, result
may share data values with original array.
Let d = filled(data, value). Returns d
masked where abs(data-value)<= atol + rtol * abs(value)
if d is of a floating point type. Otherwise returns
masked_object(d, value, copy)
"""
abs = umath.absolute
d = filled(data, value)
if issubclass(d.dtype.type, numeric.floating):
m = umath.less_equal(abs(d-value), atol+rtol*abs(value))
m = make_mask(m, flag=1)
return array(d, mask = m, copy=copy,
fill_value=value)
else:
return masked_object(d, value, copy=copy)
示例3: power
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def power (a, b, third=None):
"a**b"
if third is not None:
raise MAError("3-argument power not supported.")
ma = getmask(a)
mb = getmask(b)
m = mask_or(ma, mb)
fa = filled(a, 1)
fb = filled(b, 1)
if fb.dtype.char in typecodes["Integer"]:
return masked_array(umath.power(fa, fb), m)
md = make_mask(umath.less(fa, 0), flag=1)
m = mask_or(m, md)
if m is nomask:
return masked_array(umath.power(fa, fb))
else:
fa = numeric.where(m, 1, fa)
return masked_array(umath.power(fa, fb), m)
示例4: where
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def where (condition, x, y):
"""where(condition, x, y) is x where condition is nonzero, y otherwise.
condition must be convertible to an integer array.
Answer is always the shape of condition.
The type depends on x and y. It is integer if both x and y are
the value masked.
"""
fc = filled(not_equal(condition, 0), 0)
xv = filled(x)
xm = getmask(x)
yv = filled(y)
ym = getmask(y)
d = numeric.choose(fc, (yv, xv))
md = numeric.choose(fc, (ym, xm))
m = getmask(condition)
m = make_mask(mask_or(m, md), copy=0, flag=1)
return masked_array(d, m)
示例5: sort
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def sort (x, axis = -1, fill_value=None):
"""If x does not have a mask, return a masked array formed from the
result of numeric.sort(x, axis).
Otherwise, fill x with fill_value. Sort it.
Set a mask where the result is equal to fill_value.
Note that this may have unintended consequences if the data contains the
fill value at a non-masked site.
If fill_value is not given the default fill value for x's type will be
used.
"""
if fill_value is None:
fill_value = default_fill_value (x)
d = filled(x, fill_value)
s = fromnumeric.sort(d, axis)
if getmask(x) is nomask:
return masked_array(s)
return masked_values(s, fill_value, copy=0)
示例6: fix
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def fix(x, y=None):
"""
Round to nearest integer towards zero.
Round an array of floats element-wise to nearest integer towards zero.
The rounded values are returned as floats.
Parameters
----------
x : array_like
An array of floats to be rounded
y : ndarray, optional
Output array
Returns
-------
out : ndarray of floats
The array of rounded numbers
See Also
--------
trunc, floor, ceil
around : Round to given number of decimals
Examples
--------
>>> np.fix(3.14)
3.0
>>> np.fix(3)
3.0
>>> np.fix([2.1, 2.9, -2.1, -2.9])
array([ 2., 2., -2., -2.])
"""
x = nx.asanyarray(x)
y1 = nx.floor(x)
y2 = nx.ceil(x)
if y is None:
y = nx.asanyarray(y1)
y[...] = nx.where(x >= 0, y1, y2)
return y
示例7: common_fill_value
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def common_fill_value (a, b):
"The common fill_value of a and b, if there is one, or None"
t1 = get_fill_value(a)
t2 = get_fill_value(b)
if t1 == t2: return t1
return None
# Domain functions return 1 where the argument(s) are not in the domain.
示例8: __init__
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def __init__(self, y1, y2):
"domain_check_interval(a,b)(x) = true where x < a or y > b"
self.y1 = y1
self.y2 = y2
示例9: __call__
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def __call__(self, a, b):
"Execute the call behavior."
ma = getmask(a)
mb = getmask(b)
d1 = filled(a, self.fillx)
d2 = filled(b, self.filly)
t = self.domain(d1, d2)
if fromnumeric.sometrue(t, None):
d2 = where(t, self.filly, d2)
mb = mask_or(mb, t)
m = mask_or(ma, mb)
result = self.f(d1, d2)
return masked_array(result, m)
示例10: masked_where
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def masked_where(condition, x, copy=1):
"""Return x as an array masked where condition is true.
Also masked where x or condition masked.
"""
cm = filled(condition, 1)
m = mask_or(getmask(x), cm)
return array(filled(x), copy=copy, mask=m)
示例11: masked_greater
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def masked_greater(x, value, copy=1):
"masked_greater(x, value) = x masked where x > value"
return masked_where(greater(x, value), x, copy)
示例12: masked_greater_equal
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def masked_greater_equal(x, value, copy=1):
"masked_greater_equal(x, value) = x masked where x >= value"
return masked_where(greater_equal(x, value), x, copy)
示例13: masked_less_equal
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def masked_less_equal(x, value, copy=1):
"masked_less_equal(x, value) = x masked where x <= value"
return masked_where(less_equal(x, value), x, copy)
示例14: masked_not_equal
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def masked_not_equal(x, value, copy=1):
"masked_not_equal(x, value) = x masked where x != value"
d = filled(x, 0)
c = umath.not_equal(d, value)
m = mask_or(c, getmask(x))
return array(d, mask=m, copy=copy)
示例15: masked_equal
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import where [as 别名]
def masked_equal(x, value, copy=1):
"""masked_equal(x, value) = x masked where x == value
For floating point consider masked_values(x, value) instead.
"""
d = filled(x, 0)
c = umath.equal(d, value)
m = mask_or(c, getmask(x))
return array(d, mask=m, copy=copy)