本文整理汇总了Python中sympy.Interval.intersect方法的典型用法代码示例。如果您正苦于以下问题:Python Interval.intersect方法的具体用法?Python Interval.intersect怎么用?Python Interval.intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Interval
的用法示例。
在下文中一共展示了Interval.intersect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_curve_range_intersection
# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import intersect [as 别名]
def find_curve_range_intersection(curve_1, curve_2, cut_at_inflection=False):
"""
Return intersections of x- and y-ranges of two real curves,
which are parametric curves on the xy-plane given as
(x_array, y_array), a tuple of NumPy arrays.
"""
x1, y1 = curve_1
x2, y2 = curve_2
if cut_at_inflection is True:
x1_min, x1_max = sorted([x1[0], x1[-1]])
x2_min, x2_max = sorted([x2[0], x2[-1]])
y1_min, y1_may = sorted([y1[0], y1[-1]])
y2_min, y2_may = sorted([y2[0], y2[-1]])
else:
x1_min, x1_max = numpy.sort(x1)[[0, -1]]
x2_min, x2_max = numpy.sort(x2)[[0, -1]]
y1_min, y1_may = numpy.sort(y1)[[0, -1]]
y2_min, y2_may = numpy.sort(y2)[[0, -1]]
x1_interval = Interval(x1_min, x1_max)
x2_interval = Interval(x2_min, x2_max)
y1_interval = Interval(y1_min, y1_may)
y2_interval = Interval(y2_min, y2_may)
x_range = x1_interval.intersect(x2_interval)
y_range = y1_interval.intersect(y2_interval)
return (x_range, y_range)
示例2: test_measure
# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import intersect [as 别名]
def test_measure():
a = Symbol('a', real=True)
assert Interval(1, 3).measure == 2
assert Interval(0, a).measure == a
assert Interval(1, a).measure == a - 1
assert Union(Interval(1, 2), Interval(3, 4)).measure == 2
assert Union(Interval(1, 2), Interval(3, 4), FiniteSet(5, 6, 7)).measure \
== 2
assert FiniteSet(1, 2, oo, a, -oo, -5).measure == 0
assert S.EmptySet.measure == 0
square = Interval(0, 10) * Interval(0, 10)
offsetsquare = Interval(5, 15) * Interval(5, 15)
band = Interval(-oo, oo) * Interval(2, 4)
assert square.measure == offsetsquare.measure == 100
assert (square + offsetsquare).measure == 175 # there is some overlap
assert (square - offsetsquare).measure == 75
assert (square * FiniteSet(1, 2, 3)).measure == 0
assert (square.intersect(band)).measure == 20
assert (square + band).measure == oo
assert (band * FiniteSet(1, 2, 3)).measure == nan
示例3: test_union
# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import intersect [as 别名]
def test_union():
assert Union(Interval(1, 2), Interval(2, 3)) == Interval(1, 3)
assert Union(Interval(1, 2), Interval(2, 3, True)) == Interval(1, 3)
assert Union(Interval(1, 3), Interval(2, 4)) == Interval(1, 4)
assert Union(Interval(1, 2), Interval(1, 3)) == Interval(1, 3)
assert Union(Interval(1, 3), Interval(1, 2)) == Interval(1, 3)
assert Union(Interval(1, 3, False, True), Interval(1, 2)) == \
Interval(1, 3, False, True)
assert Union(Interval(1, 3), Interval(1, 2, False, True)) == Interval(1, 3)
assert Union(Interval(1, 2, True), Interval(1, 3)) == Interval(1, 3)
assert Union(Interval(1, 2, True), Interval(1, 3, True)) == \
Interval(1, 3, True)
assert Union(Interval(1, 2, True), Interval(1, 3, True, True)) == \
Interval(1, 3, True, True)
assert Union(Interval(1, 2, True, True), Interval(1, 3, True)) == \
Interval(1, 3, True)
assert Union(Interval(1, 3), Interval(2, 3)) == Interval(1, 3)
assert Union(Interval(1, 3, False, True), Interval(2, 3)) == \
Interval(1, 3)
assert Union(Interval(1, 2, False, True), Interval(2, 3, True)) != \
Interval(1, 3)
assert Union(Interval(1, 2), S.EmptySet) == Interval(1, 2)
assert Union(S.EmptySet) == S.EmptySet
assert Union(Interval(0, 1), [FiniteSet(1.0/n) for n in range(1, 10)]) == \
Interval(0, 1)
assert Interval(1, 2).union(Interval(2, 3)) == \
Interval(1, 2) + Interval(2, 3)
assert Interval(1, 2).union(Interval(2, 3)) == Interval(1, 3)
assert Union(Set()) == Set()
assert FiniteSet(1) + FiniteSet(2) + FiniteSet(3) == FiniteSet(1, 2, 3)
assert FiniteSet('ham') + FiniteSet('eggs') == FiniteSet('ham', 'eggs')
assert FiniteSet(1, 2, 3) + S.EmptySet == FiniteSet(1, 2, 3)
assert FiniteSet(1, 2, 3) & FiniteSet(2, 3, 4) == FiniteSet(2, 3)
assert FiniteSet(1, 2, 3) | FiniteSet(2, 3, 4) == FiniteSet(1, 2, 3, 4)
x = Symbol("x")
y = Symbol("y")
z = Symbol("z")
assert S.EmptySet | FiniteSet(x, FiniteSet(y, z)) == \
FiniteSet(x, FiniteSet(y, z))
# Test that Intervals and FiniteSets play nicely
assert Interval(1, 3) + FiniteSet(2) == Interval(1, 3)
assert Interval(1, 3, True, True) + FiniteSet(3) == \
Interval(1, 3, True, False)
X = Interval(1, 3) + FiniteSet(5)
Y = Interval(1, 2) + FiniteSet(3)
XandY = X.intersect(Y)
assert 2 in X and 3 in X and 3 in XandY
assert XandY.is_subset(X) and XandY.is_subset(Y)
raises(TypeError, lambda: Union(1, 2, 3))
assert X.is_iterable is False
示例4: WordInterval
# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import intersect [as 别名]
class WordInterval(object):
SILENCE_WORD = '#'
def __init__(self, inf, sup, word):
self.word = word
self.interval = Interval(inf, sup)
@property
def is_silent(self):
return self.word == WordInterval.SILENCE_WORD
@property
def inf(self):
return self.interval.inf
@property
def sup(self):
return self.interval.sup
def intersect(self, another_interval):
return self.interval.intersect(another_interval)
def __eq__(self, other):
return (self.interval == other.interval) and (self.word == other.word)
def __str__(self):
return "%s -> %s" % (self.interval, self.word)
def __repr__(self):
return self.__str__()
示例5: test_complement
# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import intersect [as 别名]
def test_complement():
assert Interval(0, 1).complement == \
Union(Interval(-oo, 0, True, True), Interval(1, oo, True, True))
assert Interval(0, 1, True, False).complement == \
Union(Interval(-oo, 0, True, False), Interval(1, oo, True, True))
assert Interval(0, 1, False, True).complement == \
Union(Interval(-oo, 0, True, True), Interval(1, oo, False, True))
assert Interval(0, 1, True, True).complement == \
Union(Interval(-oo, 0, True, False), Interval(1, oo, False, True))
assert -S.EmptySet == S.EmptySet.complement
assert ~S.EmptySet == S.EmptySet.complement
assert S.EmptySet.complement == Interval(-oo, oo)
assert Union(Interval(0, 1), Interval(2, 3)).complement == \
Union(Interval(-oo, 0, True, True), Interval(1, 2, True, True),
Interval(3, oo, True, True))
assert FiniteSet(0).complement == Union(Interval(-oo,0, True,True) ,
Interval(0,oo, True, True))
assert (FiniteSet(5) + Interval(S.NegativeInfinity, 0)).complement == \
Interval(0, 5, True, True) + Interval(5, S.Infinity, True,True)
assert FiniteSet(1,2,3).complement == Interval(S.NegativeInfinity,1, True,True) + Interval(1,2, True,True) + Interval(2,3, True,True) + Interval(3,S.Infinity, True,True)
X = Interval(1,3)+FiniteSet(5)
assert X.intersect(X.complement) == S.EmptySet
示例6: test_union
# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import intersect [as 别名]
def test_union():
assert Union(Interval(1, 2), Interval(2, 3)) == Interval(1, 3)
assert Union(Interval(1, 2), Interval(2, 3, True)) == Interval(1, 3)
assert Union(Interval(1, 3), Interval(2, 4)) == Interval(1, 4)
assert Union(Interval(1, 2), Interval(1, 3)) == Interval(1, 3)
assert Union(Interval(1, 3), Interval(1, 2)) == Interval(1, 3)
assert Union(Interval(1, 3, False, True), Interval(1, 2)) == \
Interval(1, 3, False, True)
assert Union(Interval(1, 3), Interval(1, 2, False, True)) == Interval(1, 3)
assert Union(Interval(1, 2, True), Interval(1, 3)) == Interval(1, 3)
assert Union(Interval(1, 2, True), Interval(1, 3, True)) == Interval(1, 3, True)
assert Union(Interval(1, 2, True), Interval(1, 3, True, True)) == \
Interval(1, 3, True, True)
assert Union(Interval(1, 2, True, True), Interval(1, 3, True)) == \
Interval(1, 3, True)
assert Union(Interval(1, 3), Interval(2, 3)) == Interval(1, 3)
assert Union(Interval(1, 3, False, True), Interval(2, 3)) == \
Interval(1, 3)
assert Union(Interval(1, 2, False, True), Interval(2, 3, True)) != \
Interval(1, 3)
assert Union(Interval(1, 2), S.EmptySet) == Interval(1, 2)
assert Union(S.EmptySet) == S.EmptySet
assert Union(Interval(0,1), [FiniteSet(1.0/n) for n in range(1,10)]) == \
Interval(0,1)
assert Interval(1, 2).union(Interval(2, 3)) == \
Interval(1, 2) + Interval(2, 3)
assert Interval(1, 2).union(Interval(2, 3)) == Interval(1, 3)
assert Union(Set()) == Set()
assert FiniteSet(1) + FiniteSet(2) + FiniteSet(3) == FiniteSet(1,2,3)
assert FiniteSet(['ham']) + FiniteSet(['eggs']) == FiniteSet('ham', 'eggs')
assert FiniteSet(1,2,3) + S.EmptySet == FiniteSet(1,2,3)
assert FiniteSet(1,2,3) & FiniteSet(2,3,4) == FiniteSet(2,3)
assert FiniteSet(1,2,3) | FiniteSet(2,3,4) == FiniteSet(1,2,3,4)
# Test that Intervals and FiniteSets play nicely
assert Interval(1,3) + FiniteSet(2) == Interval(1,3)
assert Interval(1,3, True,True) + FiniteSet(3) == Interval(1,3, True,False)
X = Interval(1,3)+FiniteSet(5)
Y = Interval(1,2)+FiniteSet(3)
XandY = X.intersect(Y)
assert 2 in X and 3 in X and 3 in XandY
assert X.subset(XandY) and Y.subset(XandY)
raises(TypeError, "Union(1, 2, 3)")
示例7: test_complement
# 需要导入模块: from sympy import Interval [as 别名]
# 或者: from sympy.Interval import intersect [as 别名]
def test_complement():
assert Interval(0, 1).complement == \
Union(Interval(-oo, 0, True, True), Interval(1, oo, True, True))
assert Interval(0, 1, True, False).complement == \
Union(Interval(-oo, 0, True, False), Interval(1, oo, True, True))
assert Interval(0, 1, False, True).complement == \
Union(Interval(-oo, 0, True, True), Interval(1, oo, False, True))
assert Interval(0, 1, True, True).complement == \
Union(Interval(-oo, 0, True, False), Interval(1, oo, False, True))
assert -S.EmptySet == S.EmptySet.complement
assert ~S.EmptySet == S.EmptySet.complement
assert S.EmptySet.complement == S.UniversalSet
assert S.UniversalSet.complement == S.EmptySet
assert Union(Interval(0, 1), Interval(2, 3)).complement == \
Union(Interval(-oo, 0, True, True), Interval(1, 2, True, True),
Interval(3, oo, True, True))
assert FiniteSet(0).complement == Union(Interval(-oo, 0, True, True),
Interval(0, oo, True, True))
assert (FiniteSet(5) + Interval(S.NegativeInfinity, 0)).complement == \
Interval(0, 5, True, True) + Interval(5, S.Infinity, True, True)
assert FiniteSet(1, 2, 3).complement == \
Interval(S.NegativeInfinity, 1, True, True) + Interval(1, 2, True, True) + \
Interval(2, 3, True, True) + Interval(3, S.Infinity, True, True)
X = Interval(1, 3) + FiniteSet(5)
assert X.intersect(X.complement) == S.EmptySet
square = Interval(0, 1) * Interval(0, 1)
notsquare = square.complement
assert all(pt in square for pt in [(0, 0), (.5, .5), (1, 0), (1, 1)])
assert not any(
pt in notsquare for pt in [(0, 0), (.5, .5), (1, 0), (1, 1)])
assert not any(pt in square for pt in [(-1, 0), (1.5, .5), (10, 10)])
assert all(pt in notsquare for pt in [(-1, 0), (1.5, .5), (10, 10)])