python image函数_python shuffle函数

python image函数_python shuffle函数Python的sympy库中ImageSet()函数与imageset()函数的用处及其区别_imageset函数

python

①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)xself}

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.

This function is not normally called directly, but is called from
imageset.

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, x**2), N) # {x**2 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官网

今天的文章python image函数_python shuffle函数分享到此就结束了,感谢您的阅读。

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

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注