performance

Find the optimal clipped circle

Find the optimal clipped circle Question: Given a NxN integer lattice, I want to find the clipped circle which maximizes the sum of its interior lattice point values. Each lattice point (i,j) has a value V(i,j) and are stored in the following matrix V: [[ 1, 1, -3, 0, 0, 3, -1, 3, -3, 2], …

Total answers: 3

Faster way to pass a numpy array through a protobuf message

Faster way to pass a numpy array through a protobuf message Question: I have a 921000 x 3 numpy array (921k 3D points, one point per row) that I am trying to pack into a protobuf message and I am running into performance issues. I have control over the protocol and can change it as …

Total answers: 1

How to optimize splitting overlapping ranges?

How to optimize splitting overlapping ranges? Question: This Python script I wrote to split overlapping ranges into unique ranges (last iteration). It produces correct output and outperforms the version in the answer. I tested output against correct method’s output and output of a brute force approach. An infinite number of boxes arranged in a line …

Total answers: 1

Improving performance of resolving a solitaire math-game

Improving performance of resolving a solitaire math-game Question: A bit of history: Since I was a kid, I have been playing a very easy little solitaire game to which I have never found a solution and honestly, I don’t know if there is one, but I would like to find it out with the help …

Total answers: 1

Numbers of combinations modulo m, efficiently

Numbers of combinations modulo m, efficiently Question: First of all I’m solving a programming problem rather than a math problem now. The question is Anish got an unbiased coin and he tossed it n times and he asked Gourabh to count all the number of possible outcomes with j heads, for all j from 0 …

Total answers: 3

What is the most efficient way to normalize values in a single row in pandas?

What is the most efficient way to normalize values in a single row in pandas? Question: I have two types of columns in a pandas dataframe, let’s say A and B. How to normalize the values in each row individually using the mean for each type of column efficiently? I can first calculate mean for …

Total answers: 3

Replacing loop variables requires time (when instantiating a wrapper)

Replacing loop variables requires time (when instantiating a wrapper) Question: Why can’t I instantiate this List wrapper in constant time? The list is already created (and not a generator), and I’m just saving it in my class. Lists are passed by reference, so please explain. I’m really confused, and can’t seem to find answers. UPDATE: …

Total answers: 1

How to efficiently apply a function to every row in a dataframe

How to efficiently apply a function to every row in a dataframe Question: Given the following table: df = pd.DataFrame({‘code’:[‘100M’,’60M10N40M’,’5S99M’,’1S25I100M’,’1D1S1I200M’]}) that looks like this: code 0 100M 1 60M10N40M 2 5S99M 3 1S25I100M 4 1D1S1I200M I’d like to convert the code column strings to numbers where M, N, D are each equivalent to (times 1), …

Total answers: 5

Efficient sums of n-length combinations of array

Efficient sums of n-length combinations of array Question: Given the following input: An integer n, e.g., 36. An list/array mylist of length m, e.g., [0.0, 24.0, 48.0, 72.0, 96.0, 120.0]. Although the values in this example are evenly spaced and integer-valued floats, they are not necessarily evenly spaced and they are in general non-negative real …

Total answers: 2