Convert xy to x*y? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am working on a project where user enters the input in the form of xy or 2x or 2ab but sympy is not able to understand that, i want to convert them into x * y, 2 * x, 2 * a * b respectively

sympy is actually able to understand that. You need to use parsing to help for it:
from sympy.parsing.sympy_parser import parse_expr
from sympy.parsing.sympy_parser import standard_transformations,\
implicit_multiplication_application
transformations = (standard_transformations +
(implicit_multiplication_application,))
print(parse_expr("xy", transformations=transformations))
Output:
x*y

Related

Are there any alternatives for the python module "random's shuffle function" in micropython? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 months ago.
Improve this question
I am currently learning micropython.
I know that in python, you can use the “random” module to shuffle a list.Furthermore, I was wondering if there's any similar function for that in micropython as well, because in the “urandom” module, that function does not exist.Any help is appreciated!
micropython can be compiled to have a randrange method available, this can be used to implement the Fisher–Yates shuffle. This is a relatively efficient in-place shuffle and can be expressed as:
from random import randrange
def shuffle(array):
"Fisher–Yates shuffle"
for i in range(len(array)-1, 0, -1):
j = randrange(i+1)
array[i], array[j] = array[j], array[i]

Solving an optimization problem with variable powers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Can anyone point me to a tool (preferably in python or c++) to solve an optimization problem where in the objective has power fractions such as :
Maximize x1^0.2 + x2^ 0.3 + x3^0.4
Thanks
I think this should be possible in python with scipy.optimize
Since it allows fractional exponentiation
4**0.5 = 2
4**0.2 = 1.3195079
and the objective function is defined as a plain python function.

How can I summarize 2 specific rows in a dataset? [Python] [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
this is a part of my dataset:
img
I would like to sum the 2 rows that present "Trentino Alto Adige" both in order to have one single row, preserving the "Date" column.
I tried to do this using the groupby and sum functions but it does not work.
This is my attempt:
df = df.groupby(["Date"],["Region"]).sum()
The output is:
TypeError: unhashable type: 'list'
How should I rewrite my code? Thank you
Your groupby is not properly written, it should be:
df = df.groupby(["Date", "Region"]).sum()

Where to find Natural neighbor interpolation in python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Does anyone know of any tools to do a natural neighbor interpolation in python? unless i'm being stupid, i can't seem to find it in the scipy.interpolate module
Here is a 3D discrete natural neighbor implementation:
https://github.com/innolitics/natural-neighbor-interpolation
Note that the "discrete" is important here; it is an approximation of the true geometric natural neighbor.

python matrix linear differential equation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have matrix differential equation diff(x) = A * x, x(0) = C, where:
x is 1 * N
A is N * N, and is a constant matrix.
I want to solve it with python. By the time I have found ways to get only approximate solutions, but I want to get an exact solution. What library can do it for me?
You can use sympy for symbolic mathematics in Python. In particular, look at sympy documentation on ODEs.

Categories