本文整理汇总了Python中numpy.logical_or方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.logical_or方法的具体用法?Python numpy.logical_or怎么用?Python numpy.logical_or使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.logical_or方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: almost_equal_ignore_nan
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def almost_equal_ignore_nan(a, b, rtol=None, atol=None):
"""Test that two NumPy arrays are almost equal (ignoring NaN in either array).
Combines a relative and absolute measure of approximate eqality.
If either the relative or absolute check passes, the arrays are considered equal.
Including an absolute check resolves issues with the relative check where all
array values are close to zero.
Parameters
----------
a : np.ndarray
b : np.ndarray
rtol : None or float
The relative threshold. Default threshold will be used if set to ``None``.
atol : None or float
The absolute threshold. Default threshold will be used if set to ``None``.
"""
a = np.copy(a)
b = np.copy(b)
nan_mask = np.logical_or(np.isnan(a), np.isnan(b))
a[nan_mask] = 0
b[nan_mask] = 0
return almost_equal(a, b, rtol, atol)
示例2: assert_almost_equal_ignore_nan
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def assert_almost_equal_ignore_nan(a, b, rtol=None, atol=None, names=('a', 'b')):
"""Test that two NumPy arrays are almost equal (ignoring NaN in either array).
Combines a relative and absolute measure of approximate eqality.
If either the relative or absolute check passes, the arrays are considered equal.
Including an absolute check resolves issues with the relative check where all
array values are close to zero.
Parameters
----------
a : np.ndarray
b : np.ndarray
rtol : None or float
The relative threshold. Default threshold will be used if set to ``None``.
atol : None or float
The absolute threshold. Default threshold will be used if set to ``None``.
"""
a = np.copy(a)
b = np.copy(b)
nan_mask = np.logical_or(np.isnan(a), np.isnan(b))
a[nan_mask] = 0
b[nan_mask] = 0
assert_almost_equal(a, b, rtol, atol, names)
示例3: test_class
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def test_class(self):
"""Tests container behavior."""
model = kproxy_supercell.TDProxy(self.model_krhf, "hf", [self.k, 1, 1], density_fitting_hf)
model.nroots = self.td_model_krhf.nroots
assert not model.fast
model.kernel()
testing.assert_allclose(model.e, self.td_model_krhf.e, atol=1e-5)
# Test real
testing.assert_allclose(model.e.imag, 0, atol=1e-8)
nocc = nvirt = 4
testing.assert_equal(model.xy.shape, (len(model.e), 2, self.k, self.k, nocc, nvirt))
# Test only non-degenerate roots
d = abs(model.e[1:] - model.e[:-1]) < 1e-8
d = numpy.logical_or(numpy.concatenate(([False], d)), numpy.concatenate((d, [False])))
d = numpy.logical_not(d)
assert_vectors_close(self.td_model_krhf.xy[d], model.xy[d], atol=1e-5)
示例4: make_sessions
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def make_sessions(data, session_th=30 * 60, is_ordered=False, user_key='user_id', item_key='item_id', time_key='ts'):
"""Assigns session ids to the events in data without grouping keys"""
if not is_ordered:
# sort data by user and time
data.sort_values(by=[user_key, time_key], ascending=True, inplace=True)
# compute the time difference between queries
tdiff = np.diff(data[time_key].values)
# check which of them are bigger then session_th
split_session = tdiff > session_th
split_session = np.r_[True, split_session]
# check when the user chenges is data
new_user = data['user_id'].values[1:] != data['user_id'].values[:-1]
new_user = np.r_[True, new_user]
# a new sessions stars when at least one of the two conditions is verified
new_session = np.logical_or(new_user, split_session)
# compute the session ids
session_ids = np.cumsum(new_session)
data['session_id'] = session_ids
return data
示例5: load_test_data
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def load_test_data(chunksize=350000*2):
types_dict_test = {
'test_id': 'int32',
'item_condition_id': 'int32',
'shipping': 'int8',
'name': 'str',
'brand_name': 'str',
'item_description': 'str',
'category_name': 'str',
}
chunks = pd.read_csv('../input/test.tsv', delimiter='\t',
low_memory=True, dtype=types_dict_test,
chunksize=chunksize)
for df in chunks:
df.rename(columns={"test_id": "id"}, inplace=True)
df.rename(columns={"item_description": "item_desc"}, inplace=True)
df["missing_brand_name"] = df["brand_name"].isnull().astype(int)
df["missing_category_name"] = df["category_name"].isnull().astype(int)
missing_ind = np.logical_or(df["item_desc"].isnull(),
df["item_desc"].str.lower().str.contains("no\s+description\s+yet"))
df["missing_item_desc"] = missing_ind.astype(int)
df["item_desc"][missing_ind] = df["name"][missing_ind]
yield df
示例6: fit
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def fit(self, magnitude, error):
n = len(magnitude)
weighted_mean = np.average(magnitude, weights=1 / error ** 2)
# Standard deviation with respect to the weighted mean
var = sum((magnitude - weighted_mean) ** 2)
std = np.sqrt((1.0 / (n - 1)) * var)
count = np.sum(
np.logical_or(
magnitude > weighted_mean + std,
magnitude < weighted_mean - std,
)
)
return {"Beyond1Std": float(count) / n}
示例7: test_object_logical
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def test_object_logical(self):
a = np.array([3, None, True, False, "test", ""], dtype=object)
assert_equal(np.logical_or(a, None),
np.array([x or None for x in a], dtype=object))
assert_equal(np.logical_or(a, True),
np.array([x or True for x in a], dtype=object))
assert_equal(np.logical_or(a, 12),
np.array([x or 12 for x in a], dtype=object))
assert_equal(np.logical_or(a, "blah"),
np.array([x or "blah" for x in a], dtype=object))
assert_equal(np.logical_and(a, None),
np.array([x and None for x in a], dtype=object))
assert_equal(np.logical_and(a, True),
np.array([x and True for x in a], dtype=object))
assert_equal(np.logical_and(a, 12),
np.array([x and 12 for x in a], dtype=object))
assert_equal(np.logical_and(a, "blah"),
np.array([x and "blah" for x in a], dtype=object))
assert_equal(np.logical_not(a),
np.array([not x for x in a], dtype=object))
assert_equal(np.logical_or.reduce(a), 3)
assert_equal(np.logical_and.reduce(a), None)
示例8: test_NotImplemented_not_returned
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def test_NotImplemented_not_returned(self):
# See gh-5964 and gh-2091. Some of these functions are not operator
# related and were fixed for other reasons in the past.
binary_funcs = [
np.power, np.add, np.subtract, np.multiply, np.divide,
np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
np.logical_and, np.logical_or, np.logical_xor, np.maximum,
np.minimum, np.mod,
np.greater, np.greater_equal, np.less, np.less_equal,
np.equal, np.not_equal]
a = np.array('1')
b = 1
c = np.array([1., 2.])
for f in binary_funcs:
assert_raises(TypeError, f, a, b)
assert_raises(TypeError, f, c, a)
示例9: test_truth_table_logical
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def test_truth_table_logical(self):
# 2, 3 and 4 serves as true values
input1 = [0, 0, 3, 2]
input2 = [0, 4, 0, 2]
typecodes = (np.typecodes['AllFloat']
+ np.typecodes['AllInteger']
+ '?') # boolean
for dtype in map(np.dtype, typecodes):
arg1 = np.asarray(input1, dtype=dtype)
arg2 = np.asarray(input2, dtype=dtype)
# OR
out = [False, True, True, True]
for func in (np.logical_or, np.maximum):
assert_equal(func(arg1, arg2).astype(bool), out)
# AND
out = [False, False, False, True]
for func in (np.logical_and, np.minimum):
assert_equal(func(arg1, arg2).astype(bool), out)
# XOR
out = [False, True, True, False]
for func in (np.logical_xor, np.not_equal):
assert_equal(func(arg1, arg2).astype(bool), out)
示例10: indexSearch
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def indexSearch(self, indexes):
"""Filters the data by a list of indexes.
Args:
indexes (list of int): List of index numbers to return.
Returns:
list: A list containing all indexes with filtered data. Matches will
be `True`, the remaining items will be `False`. If the dataFrame
is empty, an empty list will be returned.
"""
if not self._dataFrame.empty:
filter0 = self._dataFrame.index == -9999
for index in indexes:
filter1 = self._dataFrame.index == index
filter0 = np.logical_or(filter0, filter1)
return filter0
else:
return []
示例11: _get_random_batch
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def _get_random_batch(self, size, zero_prob):
idx = np.random.randint(len(self.data_x), size=size)
x = self.data_x[idx]
y = self.data_y[idx]
p = self.hpc_p[idx]
n = self.data_n[idx]
m = Environment._random_mask(size, zero_prob) * ~n # can take only available features
s = Environment._get_state(x, m)
a = ~np.logical_or(m, n) # available actions
c = np.sum(a * self.costs * config.FEATURE_FACTOR, axis=1) # cost of remaining actions
return (s, x, y, p, c)
#==============================
示例12: cou_mask
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def cou_mask(mask_est, mask_gt):
"""Complement over Union of 2D binary masks.
:param mask_est: hxw ndarray with the estimated mask.
:param mask_gt: hxw ndarray with the ground-truth mask.
:return: The calculated error.
"""
mask_est_bool = mask_est.astype(np.bool)
mask_gt_bool = mask_gt.astype(np.bool)
inter = np.logical_and(mask_gt_bool, mask_est_bool)
union = np.logical_or(mask_gt_bool, mask_est_bool)
union_count = float(union.sum())
if union_count > 0:
e = 1.0 - inter.sum() / union_count
else:
e = 1.0
return e
示例13: estimate_visib_mask_est
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def estimate_visib_mask_est(d_test, d_est, visib_gt, delta, visib_mode='bop19'):
"""Estimates a mask of the visible object surface in the estimated pose.
For an explanation of why the visibility mask is calculated differently for
the estimated and the ground-truth pose, see equation (14) and related text in
Hodan et al., On Evaluation of 6D Object Pose Estimation, ECCVW'16.
:param d_test: Distance image of a scene in which the visibility is estimated.
:param d_est: Rendered distance image of the object model in the est. pose.
:param visib_gt: Visibility mask of the object model in the GT pose (from
function estimate_visib_mask_gt).
:param delta: Tolerance used in the visibility test.
:param visib_mode: See _estimate_visib_mask.
:return: Visibility mask.
"""
visib_est = _estimate_visib_mask(d_test, d_est, delta, visib_mode)
visib_est = np.logical_or(visib_est, np.logical_and(visib_gt, d_est > 0))
return visib_est
示例14: test_NotImplemented_not_returned
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def test_NotImplemented_not_returned(self):
# See gh-5964 and gh-2091. Some of these functions are not operator
# related and were fixed for other reasons in the past.
binary_funcs = [
np.power, np.add, np.subtract, np.multiply, np.divide,
np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
np.logical_and, np.logical_or, np.logical_xor, np.maximum,
np.minimum, np.mod
]
# These functions still return NotImplemented. Will be fixed in
# future.
# bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]
a = np.array('1')
b = 1
for f in binary_funcs:
assert_raises(TypeError, f, a, b)
示例15: _match_nans
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import logical_or [as 别名]
def _match_nans(a, b, weights):
"""
Considers missing values pairwise. If a value is missing
in a, the corresponding value in b is turned to nan, and
vice versa.
Returns
-------
a, b, weights : ndarray
a, b, and weights (if not None) with nans placed at
pairwise locations.
"""
if np.isnan(a).any() or np.isnan(b).any():
# Find pairwise indices in a and b that have nans.
idx = np.logical_or(np.isnan(a), np.isnan(b))
a[idx], b[idx] = np.nan, np.nan
if weights is not None:
weights = weights.copy()
weights[idx] = np.nan
return a, b, weights