Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 123200

Performance is a subset of Optimization: performance is the goal when you want the execution time of your program or routine to be optimal.

2 votes
Accepted

Leftmost bisect search to find valid perfect square

Some small points: ternary expression No need for return True if lo ** 2 == num else False. you can use just return lo ** 2 == num early return If mid**2 == num, you can return early: sq = mid ** …
Maarten Fabré's user avatar
6 votes

Optimization of algorithm performance

import * Since you only need sqrt and log10 from math, I would change this: from math import * to: from math import sqrt, log10 PEP8 Use descriptive method names. I have no idea what dl or c mean V …
Maarten Fabré's user avatar
6 votes
Accepted

Pandas add calculated row for every row in a dataframe

This can lead to unexpected loss of information (large ints converted to floats), or loss in performance (object dtype). …
Maarten Fabré's user avatar
4 votes
Accepted

Merge multiple pandas dataframe along with np.where to process values

keyword arguments I had to check the documentation to find out what the 1 means in df1.drop('new_id', 1). More clear would be df1.drop('new_id', axis=1), or even better: df1.drop(columns=["type_", "ne …
Maarten Fabré's user avatar
4 votes

function future_returns for data-driven bond screening

code Your code itself is clear, with and has only a few improvements df your parameter df expects actually a Series, and not a DataFrame, so I would rename this. composition now you first make an …
Maarten Fabré's user avatar
8 votes

Go (board game) check for removed stones

Performance I think the main reason why the algorithm is slow, is because you start a new flood fill for every empty place on the board. …
Maarten Fabré's user avatar
2 votes
Accepted

Generation of products of power

if p ** a * primes[i+1] **b * primes[i+2] ** c > limit: return then I also used primes as a local variable by changing the signature: def generate4b(a, b, c, limit, primes): Performance
Maarten Fabré's user avatar
6 votes
Accepted

Calculate probability of dice total

import why import product within your method, and not in the module scope? instantiation There is just no reason to instantiate the list in choices = list(product(range(1, faces+1), repeat=dice) …
Maarten Fabré's user avatar
7 votes

Performance for simple code that converts a RGB tuple to hex string

memoization The _channel_to_hex is called 3 times per pixel. It only takes 256 different inputs, so a logical first step would be to memoize the results. This can be done with either functools.lru_ca …
Maarten Fabré's user avatar
3 votes
Accepted

Count number of unique adjacent cells in a matrix

bug in count_adjacent_islands, number_of_islands = 0 should be number_of_countries = 0 mutate original argument Most of the time, it's a bad idea to change any of the arguments to a function unless …
Maarten Fabré's user avatar
3 votes

How to do these extraction/computations efficiently?

Python is rather slow for iterations. If your data is in a pandas Dataframe, try to do things as vectorised as possible. You even iterate over the complete dataset for each row of your dataset, for ea …
Maarten Fabré's user avatar
2 votes
Accepted

Initial Mass Function for young star clusters and disk field stars

Class You use classes here without any benefit. Your methods don't use the self argument. If you use the class as a namespace, I would suggest you use a module. np Convention is to do import numpy …
Maarten Fabré's user avatar
3 votes

More elegant way to count anagrams in Python?

Additionally to mcocdawc's answer, since what I mean is too much for a comment You need an intermediate stage. You used the list of Counters for this. But then to find anagrams in the list is expens …
Maarten Fabré's user avatar
5 votes
Accepted

Trimming blank space from images

Split the code This long method does a lot of things: it reads the file preprocesses it searches for the bounding box of the area of interest crops the result writes the result to a file Better …
Maarten Fabré's user avatar
4 votes
Accepted

Vectorized crosstabulation in Python for two arrays with two categories each

Algorithm If you look at your code, and follow the if-elif part, you see that there are 4 combinations of i and j i j : result True, True : A False, True : B True, False : C False, False …
Maarten Fabré's user avatar

15 30 50 per page