performance

How is that pandas is faster than pure C in the groupby operation?

How is that pandas is faster than pure C in the groupby operation? Question: I have an nparray of x,y pairs with shape (n,2), and knowing for certain that for each x there are multiple values of y , I wanted to calculate the average value of y for each unique x. It occurred to …

Total answers: 1

I need help to speed up of a Python for-loop with huge amount of calculations

I need help to speed up of a Python for-loop with huge amount of calculations Question: I am working on a pice of Python software that requires to run a huge amount of calculations. I am talking about up to hundred of millions of calculations or more (n in below code can be 100000 or …

Total answers: 3

Dataframe of start and end dates into sum of days in an array of periods

Dataframe of start and end dates into sum of days in an array of periods Question: I have a pandas data frame of start and end dates for contracts. I want to work out the number of in force contract days for all periods (e.g. months) covered by the contracts. Example input: start_date end_date 0 …

Total answers: 1

Why is 0/1 faster than False/True for this sieve in PyPy?

Why is 0/1 faster than False/True for this sieve in PyPy? Question: Similar to why use True is slower than use 1 in Python3 but I’m using pypy3 and not using the sum function. def sieve_num(n): nums = [0] * n for i in range(2, n): if i * i >= n: break if nums[i] …

Total answers: 1

Finding the longest interval with a decrease in value

Finding the longest interval with a decrease in value faster than quadratic time Question: I have a list of values for some metric, e.g.: # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [50, 52, 58, 54, 57, 51, 55, 60, 62, 65, 68, 72, 62, …

Total answers: 1

Iterating over dictionary or its items

Iterating over dictionary or its items Question: What’s a better practice and what’s faster: iterating over dictionary (practically by its keys): for key in dictionary: … or iterating over its items: for key, value in dictionary.items(): …? Using dict.items() seems to be a more clean way to iterate over a dictionary, but isn’t it slower …

Total answers: 1

Index matrix but return a list of lists Pytorch

Index matrix but return a list of lists Pytorch Question: I have a 2-dimensional tensor and I would like to index it so that the result is a list of lists. For example: R = torch.tensor([[1,2,3], [4,5,6]]) mask = torch.tensor([[1,0,0],[1,1,1]], dtype=torch.bool) output = R[mask] This makes output as tensor([1, 4, 5, 6]). However, I would …

Total answers: 1

Random dont chose 8 character words

Random dont chose 8 character words Question: I used random module in my ptoject. Im not a programmer, but i need to do a script which will create a randomized database from another database. In my case, I need the script to select random words lined up in a column from the "wordlist.txt" file, and …

Total answers: 1

Does PriorityQueue call sorted every time get is called?

Does PriorityQueue call sorted every time get is called? Question: The docs for queue.PriorityQueue say: The lowest valued entries are retrieved first (the lowest valued entry is the one returned by sorted(list(entries))[0]). Does that mean that every time I use the get method of a PriorityQueue that the elements are re-sorted? That would seem inefficient. …

Total answers: 1