optimization

Is using else faster than returning value right away?

Is using else faster than returning value right away? Question: Which of the following is faster? 1. def is_even(num: int): if num%2==0: return True else: return False def is_even(num: int): if num%2==0: return True return False I know you can technically do this: def is_even(num: int): return n%2==0 But for the sake of the question, …

Total answers: 1

Quickly assigning an id to a given combination of bits

Quickly assigning an id to a given combination of bits Question: the context behind my issue is not important, as my question itself is fairly self-contained. Im currently trying to assign numbers to sequences of bits. Such that, if i ask functionA for bit sequence 42, it would return the corresponding bits, say "0110101011…" (not …

Total answers: 3

Python filter larger text by quantile

Python filter larger text by quantile Question: Assume I am process a very large text file, I have the following pseudocode xx_valueList = [] lines=[] with line in file: xx_value = calc_xxValue(line) xx_valueList.append(xx_value) lines.append(lines) # get_quantile_value is a function return the cutoff value with a specific quantile precent cut_offvalue = get_quantile_value(xx_valueList, precent=0.05) for line in …

Total answers: 1

How to prioritize main pyqt5 thread in python3?

How to prioritize main pyqt5 thread in python3? Question: I have made a gui application with PyQt5 in python 3.8. But when I order from my GUI to perform heavy multithreaded CPU-intensive task (the gui thread isn’t engaged), the GUI becomes very non-responsive (most likely due to CPU being concentrated on worker tasks). My question …

Total answers: 1

Minimizing a function using PyTorch Optimizer – Return values are all the same

Minimizing a function using PyTorch Optimizer – Return values are all the same Question: I’m trying to minimize a function in order to better understand the optimizer process. As an example I used the Eggholder-Function (https://www.sfu.ca/~ssurjano/egg.html) which is 2d. My goal is to get the values of my parameters (x and y) after every optimizer …

Total answers: 2

Optimizing the speed of a python program that uses PyQt5 and images

Optimizing the speed of a python program that uses PyQt5 and images Question: I’m trying to create a python program that let me visualize a stylized fictional political map where each country is represented by pixel of a specific color. I’m using PyQt5 to create some kind of simple GUI that let me open the …

Total answers: 1

PuLP Conditional Sum based on key of the loop

PuLP Conditional Sum based on key of the loop Question: I am trying to use this conditional sum in Pulp’s objective function. For the second lpSum, I am trying to calculate the costs of when we don’t have enough chassis’ to cover the demand and will need pool chassis’ with a higher costs. Of course, …

Total answers: 1

PuLP Optimization Problem: fitting items into crates with restrictions

PuLP Optimization Problem: fitting items into crates with restrictions Question: I would like some assistance with an optimization problem in Python.. Here is some background: Objective is to minimize the number of Crates (c) needed while satisfying Unit_ids (u) needed. Each crate contains any number (from 0-inf) number of different types of Units, with varying …

Total answers: 1