Python | sympy.expand () метод
With the help of sympy.expand() method, we can expand the mathematical expressions in the form of variables by using sympy.expand() method.
Syntax :
sympy.expand(expression)
Return : Return mathematical expression.
Example #1 :
In this example we can see that by using sympy.expand() method, we can get the mathematical expression with variables. Here we use symbols() method also to declare a variable as symbol.
# import sympyfrom sympy import expand, symbols x, y = symbols("x y")gfg_exp = x + y # Use sympy.expand() methodexp = sympy.expand(gfg_exp**2) print(exp) |
Выход :
x**2 + 2*x*y + y**2
Example #2 :
# import sympyfrom sympy import expand, symbols x, y, z = symbols("x y z")gfg_exp = x + y + z # Use sympy.expand() methodexp = sympy.expand(gfg_exp**2) print(exp) |
Выход :
x**2 + 2*x*y + 2*x*z + y**2 + 2*y*z + z**2
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.