Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何仅从数组中选择实数?(Python 3)_Python_Arrays_Sympy_Complex Numbers_Real Number - Fatal编程技术网

如何仅从数组中选择实数?(Python 3)

如何仅从数组中选择实数?(Python 3),python,arrays,sympy,complex-numbers,real-number,Python,Arrays,Sympy,Complex Numbers,Real Number,我想找到垂直渐近线: f=3x^3+17x^2+6x+1/2x^3-x+3 所以我想找到2x^3-x+3的根,所以我写了: 结果是: 所以现在输出中唯一有意义的数字是-1.289,而复数没有任何意义 我的问题是:我如何才能只选择实数,以便输出显示: asym1 = -1.28962390148506 你可以做: asym1 = [n for n in asym1 if n.is_real][0] 复数是复数类的实例,而实数是复数类的实例 是浮动: 如果n为正怎么办?不需要,提供了各种

我想找到垂直渐近线:

f=3x^3+17x^2+6x+1/2x^3-x+3

所以我想找到2x^3-x+3的根,所以我写了:

结果是:

所以现在输出中唯一有意义的数字是-1.289,而复数没有任何意义

我的问题是:我如何才能只选择实数,以便输出显示:

asym1 = -1.28962390148506
你可以做:

asym1 = [n for n in asym1 if n.is_real][0]    

复数是复数类的实例,而实数是复数类的实例 是浮动:


如果n为正怎么办?不需要,提供了各种属性来检查实数number@dilkash,这种方法是通用的,不限于sympy。
asym1 = -1.28962390148506
asym1 = [n for n in asym1 if n.is_real][0]    
asym1 = [x for x in asym1 if isinstance(x, float)]