I’m trying some optimisation on my code and I struggle with multiple if then statements. The point is to update SQL database with psycopg2 and I must set some variables with “None” to be “null” in SQL. If I do if/elif/elif, the script will leave on the first valid condition but I want every condition to be checked, here is
Tag: optimization
is these two dictonary statments are same while looping it in for loop?
I read that my_dict.keys() returns the dynamic view to iterate over the dictionary. I usually iterate the dictionary without the keys() function. So my question is, are below two code blokes are same? if not, what performance differences do these two have (which one is more optimized) Note: I usually use python version 3.7+ so if there’s any version-wise implementation
Optimize with SciPy vector to scalar function with constraint
I would need to optimize a function f with respects to a vector x, that takes as input a constant matrix m and returns a scalar v >= 0. MWE with random numbers: How do I set up the constraint for the output value? As far as I read in the doc I can only set constraints for the inputs.
Fastest way to transform a continuous string of hex into base 10 in Python
I have a 100M 3600 character length strings of hexadecimal digits that I want to split into blocks of three and then convert into base 10. Strictly speaking, I want to transform these into signed 4 byte numbers. As I have 100M of these strings to process, my main aim is code efficiency/speed. For splitting the strings I am using
Is there another way to convert ee.Number to float except getInfo()?
Hello friends! Summarization: I got a ee.FeatureCollection containing around 8500 ee.Point-objects. I would like to calculate the distance of these points to a given coordinate, lets say (0.0, 0.0). For this i use the function geopy.distance.distance() (ref: https://geopy.readthedocs.io/en/latest/#module-geopy.distance). As input the the function takes 2 coordinates in the form of 2 tuples containing 2 floats. Problem: When i am trying
How to set the funcion timeout for Genetic Algorithm to more than 10 sec?
I have a loss function that opens an external .exe file for calculation, and running this executable file usually takes around 2 or 3 minutes. It works very well, but When I want to pass this function to the Genetic Algorithm for optimization, I face this error: So it obviously says that GA waited 10 sec and did not receive
The most efficient way rather than using np.setdiff1d and np.in1d, to remove common values of 1D arrays with unique values
I need a much faster code to remove values of an 1D array (array length ~ 10-15) that are common with another 1D array (array length ~ 1e5-5e5 –> rarely up to 7e5), which are index arrays contain integers. There is no duplicate in the arrays, and they are not sorted and the order of the values must be kept
Two constraints setting together in optimization problem
I am working on an optimization problem, and facing difficulty setting up two constraints together in Python. Hereunder, I am simplifying my problem by calculation of area and volume. Only length can be changed, other parameters should remain the same. Constraint 1: Maximum area should be 40000m2 Constraint 2: Minimum volume should be 50000m3 Here, I can set values in
Trying to change my code to include loops and listed variables to make more streamline and expandable code
I made a prior discussion where I was unable to properly explain myself. This is my most up to date code that does what I want with 3 items. I would like to turn this into a function using a list so that it can ask how many items you want to use and then run the code that I
Find cells from vertices in pyvista PolyData mesh
I have a PolyData mesh, and I am trying to color some cells that contain given vertices. However, I need an efficient way to to this. For instance, this works, but it is way too slow for a large mesh: This is what I get, which is fine…I just need to do it much faster! Answer If you have the