在本文中,我们将带你了解如何通过Python中已定义函数的平方计算积分?在这篇文章中,我们将为您详细介绍如何通过Python中已定义函数的平方计算积分?的方方面面,并解答如何通过python中已定义函
在本文中,我们将带你了解如何通过Python中已定义函数的平方计算积分?在这篇文章中,我们将为您详细介绍如何通过Python中已定义函数的平方计算积分?的方方面面,并解答如何通过python中已定义函数的平方计算积分常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的python – SymPy和复数的平方根、python – 多维数组中列的平方和的平方根、Python 自定义函数的参数、Python-如何通过使用其他函数的数据来更改函数中已声明变量的值。
本文目录一览:- 如何通过Python中已定义函数的平方计算积分?(如何通过python中已定义函数的平方计算积分)
- python – SymPy和复数的平方根
- python – 多维数组中列的平方和的平方根
- Python 自定义函数的参数
- Python-如何通过使用其他函数的数据来更改函数中已声明变量的值
如何通过Python中已定义函数的平方计算积分?(如何通过python中已定义函数的平方计算积分)
我不习惯scipy.integrate,但是根据您的解释,您应该可以做到:
integrate.quad(lambda x:function_f(x)**2,1)
python – SymPy和复数的平方根
当使用求解来计算二次方程的根时,SymPy返回可以简化的表达式,但我无法简化它们.最小的例子如下:
from sympy import *
sqrt(-24-70*I)
在这里,SymPy只返回sqrt(-24-70 * I),而Mathematica或Maple将回复相当于5-7 * I.
我知道有两个平方根,但这种行为需要SymPy,例如,将返回相当复杂的解决方案
z = symbols("z")
solve(z ** 2 + (1 + I) * z + (6 + 18 * I),z)
同时,Maple和Mathematica将很高兴地给我两个高斯整数来解决这个等式.
有没有选项或我缺少的东西?
from sympy import *
z = -24-70*I
x,y = symbols('x y',real=True)
result = solve((x+I*y)**2 - z,(x,y))
结果是[(-5,7),(5,-7)]
为方便起见,这可以包装为一个功能:
def my_sqrt(z):
x,real=True)
sol = solve((x+I*y)**2 - z,y))
return sol[0][0] + sol[0][1]*I
现在你可以使用my_sqrt(-24-70 * I)并得到-5 7 * I.
在您的示例中,相同的策略有助于使用二次方程:
x,real=True)
z = x + I*y
solve(z ** 2 + (1 + I) * z + (6 + 18 * I),y))
输出:[( – 3,3),(2,-4)]
python – 多维数组中列的平方和的平方根
我有一份清单.
l = [[0 2 8] [0 2 7] [0 2 5] [2 4 5] [ 8 4 7]]
我需要找到平方列之和的平方根.
0 2 8 0 2 7 0 2 5 2 4 5 8 4 7
输出为,
l = [sqrt((square(0) + square(0) + square(0) + square(2) + square(8)) sqrt((square(2) + square(2) + square(2) + square(4) + square(4)) sqrt((square(8) + square(7) + square(5)) + square(5) + square(7))]
解决方法
>>> import numpy as np >>> a = np.array([[0,2,8],[0,7],5],[2,4,[ 8,7]]) >>> np.sqrt(np.sum(np.square(a),axis=0)) array([ 8.24621125,6.63324958,14.56021978])
Python 自定义函数的参数
在 Python 中自定义的函数可以有三类不同的参数
- formal parameters
- positional arguments
- Keyword Arguments
When a final formal parameter of the form **name
is present, it receives a dictionary (see Mapping Types — dict) containing all keyword arguments except for those corresponding to a formal parameter. This may be combined with a formal parameter of the form *name
(described in the next subsection) which receives a tuple containing the positional arguments beyond the formal parameter list. (*name
must occur before **name
.) For example, if we define a function like this:
Python-如何通过使用其他函数的数据来更改函数中已声明变量的值
您的代码中并未实际使用全局变量。仅使用属性(self.status1
)。仅当逻辑返回True时才设置变量。另外,您应该使用init
方法来初始化类变量。
尝试以下代码:
class Test_Selenium():
def __init__(self):
self.status1 = None # starting value
def test__init__(self): # needed by pytest ?
self.status1 = None # starting value
def test_1(self):
#Selenium driver logic
if self.status1 == None: # can also use if not self.status1:
return self.test_481()
elif self.status1 == True:
print("User is asked for new authentication")
def test_481(self):
##some logic##
logic = True
if (logic): # must be true to set status1
print("User authenticated - Passed")
self.status1 = True
#self.driver.quit()
return self.test_1() # recheck status
ts = Test_Selenium()
print(ts.status1) # None
ts.test_1()
print(ts.status1) # True
输出
None
User authenticated - Passed
User is asked for new authentication
True
关于如何通过Python中已定义函数的平方计算积分?和如何通过python中已定义函数的平方计算积分的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于python – SymPy和复数的平方根、python – 多维数组中列的平方和的平方根、Python 自定义函数的参数、Python-如何通过使用其他函数的数据来更改函数中已声明变量的值等相关知识的信息别忘了在本站进行查找喔。
本文标签: