2025年Python的sympy库中ImageSet()函数与imageset()函数的用处及其区别

Python的sympy库中ImageSet()函数与imageset()函数的用处及其区别imageset 函数与 ImageSet 函数的区别 两个函数都是用于表达集合变换后的形式 其区别在于 用途不同 imageset 函数主要用于需要计算出具体值的情况 ImageSet 函数主要用于无需计算出具体值的情况 参数设置形式上的不同 详见后文

大家好,我是讯享网,很高兴认识大家。

①imageset()函数与ImageSet()函数的区别

两个函数都是用于表达集合变换后的形式,其区别在于:

  1. 用途不同
    ①imageset()函数主要用于需要计算出具体值的情况
    ②ImageSet()函数主要用于无需计算出具体值的情况
  2. 参数设置形式上的不同(详见后文)
  3. 一般情况下不直接使用ImageSet()函数而是使用imageset()函数

②imageset()函数的官方介绍

sympy.sets.sets.imageset(*args)

Return an image of the set under transformation f.

Explanation

If this function cannot compute the image, it returns an unevaluated
ImageSet object.
{ f ( x ) ∣ x ∈ s e l f } \left\{ f\left( x\right) \mid x\in self\right\} { f(x)∣x∈self}
Examples

>>>from sympy import S, Interval, imageset, sin, Lambda >>>from sympy.abc import x 

讯享网
讯享网>>>imageset(x, 2*x, Interval(0, 2)) Interval(0, 4) 
>>>imageset(lambda x: 2*x, Interval(0, 2)) Interval(0, 4) 
讯享网>>>imageset(Lambda(x, sin(x)), Interval(-2, 1)) ImageSet(Lambda(x, sin(x)), Interval(-2, 1)) 
>>>imageset(sin, Interval(-2, 1)) ImageSet(Lambda(x, sin(x)), Interval(-2, 1)) >>>imageset(lambda y: x + y, Interval(-2, 1)) ImageSet(Lambda(y, x + y), Interval(-2, 1)) 

Expressions applied to the set of Integers are simplified to show as
few negatives as possible and linear expressions are converted to a
canonical form. If this is not desirable then the unevaluated ImageSet
should be used.


讯享网

讯享网 >>>imageset(x, -2*x + 5, S.Integers) ImageSet(Lambda(x, 2*x + 1), Integers) 

③ImageSet()函数的官方介绍

class sympy.sets.fancysets.ImageSet(lambda, *sets)

Image of a set under a mathematical function. The transformation must
be given as a Lambda function which has as many arguments as the
elements of the set upon which it operates, e.g. 1 argument when
acting on the set of integers or 2 arguments when acting on a complex
region.

Examples

>>>from sympy import Symbol, S, pi, Dummy, Lambda >>>from sympy import FiniteSet, ImageSet, Interval 
讯享网>>>x = Symbol('x') >>>N = S.Naturals >>>squares = ImageSet(Lambda(x, x2), N) # {x2 for x in N} >>>4 in squares True >>>5 in squares False 
>>>FiniteSet(0, 1, 2, 3, 4, 5, 6, 7, 9, 10).intersect(squares) { 
   1, 4, 9} 
讯享网>>>square_iterable = iter(squares) >>>for i in range(4): next(square_iterable) 1 4 9 16 

If you want to get value for x=2, 1/2 etc. (Please check whether the x value is in base_set or not before passing it as args)

>>>squares.lamda(2) 4 >>>squares.lamda(S(1)/2) 1/4 
讯享网>>>n = Dummy('n') >>>solutions = ImageSet(Lambda(n, n*pi), S.Integers) # solutions of sin(x) = 0 >>>dom = Interval(-1, 1) >>>dom.intersect(solutions) { 
   0} 

sympy官网

小讯
上一篇 2025-03-14 16:03
下一篇 2025-03-21 12:35

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/86010.html