# 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], …

## 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 …

## 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 …

## 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 …

## 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 …

## Issue creating new columns based on existing columns in DataFrame – PerformanceWarning: DataFrame is highly fragmented

Issue creating new columns based on existing columns in DataFrame – PerformanceWarning: DataFrame is highly fragmented Question: I want to create X number of new columns in a pandas dataframe based on an existing column of the dataframe. I would like to create new columns that shift the values in the original column by 1 …

## 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 …

## 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: …