Automatic conversion of multi-process parallel computing
command format
Please convert the following Python code into a multi-process parallel operation --
**Python code
Examples of commands
Please convert the following Python code into a multi-process parallel operation --
import time
def calc_square(numbers).
for n in numbers.
print(f'\n{n} ^ 2 = {n*n}')
time.sleep(0.1)
def calc_cube(numbers).
for n in numbers.
print(f'\n{n} ^ 3 = {nnn}')
time.sleep(0.1)
numbers = [2, 3, 5, 8]
start = time.time()
calc_square(numbers)
calc_cube(numbers)
end = time.time()
print('Execution Time: {}'.format(end-start))
Code Efficiency Comparison
command format
Please, as a software test engineer, I would like to compare the operational efficiency of the following two pieces of algorithmic code that perform the same task, please write a loop to execute the following algorithm [ Parameters ] code, and give the execution time of each of the two pieces of code, as well as the relevant statistical information
Code 1.
Code 2.
Examples of commands
Please, as a software test engineer, I would like to compare the operational efficiency of the following two pieces of algorithmic code that perform the same task, please write a loop to execute the following algorithm [ 10 times ] code, and give the execution time of each > of the two pieces of code, as well as the related statistics
# Code 1.
def compute1(a, b).
return (a+b) / (a*b)
# Code 2.
import numpy as np
def compute2(a, b): return np.
return np.divide(np.sum([a,b]), np.multiply(a,b))
Automated Unitized Testing
command format
Please, as a software test engineer, write the [ Functions ] The unit test code for the test condition:
test condition
Examples of commands
Please, as a software test engineer, write the [ def compute(a, b) ] The unit test code for the test condition:
Input: 1, 1.2, 0.99 | Output: 1, 1.2, 0.99
Input: -1, -1.2, -0.99 | Output: 1, 1.2, 0.99
Input: 0 | Output: 0
Input: None, [], {} | Output: TypeError
Code Acceleration
command format
Please help me as a software engineer to optimize the efficiency of execution of the following code --
Python Code
Examples of commands
Please help me as a software engineer to optimize the efficiency of execution of the following code --
def test(y):
sum = 0
for i in range (y+1):
sum += 1
return sum
Pandas Code Optimization
command format
As a code optimizer, please help me optimize the following Pandas code --
Python Code
Examples of commands
As a code optimizer, please help me optimize the following Pandas code --
import pandas as pd
df = pd.read_csv(data_path + "titles.csv")
df_bad = df.query("runtime > 30 & type == 'SHOW'")
df_bad ["score"] = df_bad "imdb_score", "tmdb_score".sum(axis=1)
df_bad = df_bad "seasons", "score"
df_bad = df_bad.groupby("seasons").agg(["count", "mean"])
df_bad = df_bad.droplevel(axis=1, level=0)
df_bad = df_bad.query("count > 10")
df_bad.head()
Low-level code rewriting
command format
Please act as a code optimizer, the following code is written at a low level, please help me to change it --
Python Code
Examples of commands
Please act as a code optimizer, the following code is written at a low level, please help me to change it --
numbers = [1, 2, 3]
letters = ["A", "B", "C"]
for index in range (len(numbers))::
print(numbers[index], letters[index])
Code Simplification
command format
Please act as a code optimizer and simplify the following code --
Python Code
Examples of commands
Please act as a code optimizer and simplify the following code --
classes = ['Intro to Python',
'R Data Analysis'.
'Python Machine Learning']
grades = [98,
96,
89]
grade_dict = {}
for idx in range(len(classes))::
grade_dict[classes[idx]] = grades[idx]
print(grade_dict)
Code Troubleshooting
command format
Please, as a software engineer, help me to troubleshoot the following error in the code --
Python Code
Examples of commands
Please, as a software engineer, help me to troubleshoot the following error in the code --
def add_from_1_to_k(k).
if (k > 0).
result = k + add_from_1_to_k(k - 1)
return result
add_from_1_to_k(-10)