All Questions
Tagged with python-2.x performance
177 questions
2
votes
3
answers
607
views
Bifurcating recursive calculation with redundant calculations
def T(n):
if n <= 0:
return 1
else:
return T(n-1) + (n-1) * T(n-2)
print T(4)
I need an effective way to print out the output of the function <...
12
votes
3
answers
2k
views
Finding the prime factors of a number in Python 2
I’ve created a function that takes a number and, if it’s prime, tells you so, or if it’s composite, gives you the prime factors of the number (and if it’s 1, tells you that it’s neither).
...
0
votes
1
answer
528
views
Image color-moment extractor [closed]
I was just wondering if there is a way to speed up the performances of this for loops in Python.
I'm trying to process an image to get the color-moments without using libraries.
It takes about 12sec ...
3
votes
1
answer
291
views
Estimation of min_samples for DBSCAN
I'm attempting to speed up some python code that is supposed to automatically pick the minimum samples argument in DBSCAN. Currently the execution time grows exponentially as the number of training ...
3
votes
0
answers
294
views
Store special deals, like 3 for 2
I have to apply two deals on the cart.
Buy 3 (equal) items and pay for 2
Buy 3 (in a set of items) and the cheapest is free
Items in cart:
...
1
vote
0
answers
83
views
Reading attachment data from a PostgreSQL table with python
I have developed this script to find the counts of attachment records stored in a table in PostgreSQL for different other tables. I check if the res_id field of <...
1
vote
1
answer
206
views
Reading employee data from a PostgreSQL database
I have developed this script to read employee_language table records of a PostgreSQL database using Python 2 (due to some OS limitation). I want to find duplicate ...
1
vote
1
answer
239
views
Django view of reward points that heavily filters and sorts (many) database results
My page (even when it has no data) takes 10+ seconds to load. That's just too long, considering when you finally get to it there's no data. When it has data, it takes even longer.
Here is my view, ...
2
votes
0
answers
122
views
Extract cell values from multiband rasters
I have the following function and code snippet to extract cell values for multiple years, format it, and save to a list. Each raster has 365 bands — one for each day. A separate operation is performed ...
5
votes
1
answer
1k
views
Improving the speed of creation for three Perlin Noise Maps in Python?
I am interested in learning how I can improve the speed of the code in this pygame file. I iterate over 6400 * 1800 * 3 or 34,560,000 elements of various numpy arrays here to apply noise values to ...
7
votes
1
answer
1k
views
Plotting terrain pixels with PyGame based on random NumPy array
I am experimenting with Perlin Noise and random map generation. I have a 2D numpy ndarray full of 16-bit floats called map_list that I call from the singleton ...
2
votes
1
answer
101
views
Application to monitor device power levels for deviations
I have a high performance, computation intensive application that runs on a Centos 7 machine with Python 2.7.5.
I'll try to explain what the application does:
The application runs an infinite loop, ...
1
vote
1
answer
94
views
Python Firewall-Connection-Event Filter too slow
I've written a little piece of code to filter Firewall-Connection-Events by a certain group of IPs. But the code can't keep up since the input is fairly huge. I am looking for ways to make this code ...
2
votes
1
answer
61
views
Looping text in Python with directional control
The code is an implementation of looping text (similar to a circular buffer - wraps around when it reaches the edge of the defined bounds) with directional control.
The code is functional and works ...
-1
votes
1
answer
248
views
Decoding a string encoded by Caesar Cipher and some delimiters [closed]
I have the following code which I seek to optimize. The result of the bruteforce I already have but I'm just trying to learn some more python using the same example.
The code in the data needs to be ...
0
votes
1
answer
147
views
Printing all the factors as well as the prime factors of a given number using Python 2.7.x
Okay here is my maiden attempt at programming using Python 2.7. I need help or feedback on this code:
How do I know about the processing cycles this program consumes?
How do I implement this idea ...
2
votes
3
answers
2k
views
Given a sorted array nums, remove the duplicates in-place
I wrote an algorithm to solve this challenge but would love some feedback on its efficiency and, if you were an interviewer, what your opinion would be on my solution. I believe my time complexity is \...
4
votes
2
answers
79
views
Pulling log messages from a MySQL table
I want to get this code reviewed for a function I wrote that pulls log messages from a MySQL table:
...
6
votes
1
answer
437
views
Add an edge to a graph to minimize the average shortest path length
This program is used to find the nodes in a grid network, between which, if an edge is added, the average shortest path length of the entire grid reduces by the most.
"Average shortest path length" ...
4
votes
1
answer
846
views
Relative frequency of words in tree of documents
I have a tree structure where at every node there is a list of documents (document length can vary from 5 to 500), and each document contains a number of words.
I want to calculate relative frequency ...
1
vote
2
answers
70
views
Reclassifying movies by theme
Any efficient way to solve the following problem assuming data is large. I solved the problem but how can I improve the code, which will make it efficient. any suggestions?
Data:
...
4
votes
1
answer
593
views
One minute cron Python script reads from MySQL and updates Redis based on calculations
The following code works and will be put into cron on a AWS server (not sure what specifications, cores, kernels etc) at a every 1 minute frequency.
However, it's my first time putting a script into ...
3
votes
2
answers
183
views
Littlewood Polynomial Heatmap
The following Python program generates heat maps of the roots of Littlewood polynomials. It works fine with a small number of roots, however I tried to use 2^21 in the first loop and it ate up 12 ...
4
votes
3
answers
3k
views
os.walk listing directory
I use this script to get a list of all my photos in a folder and its subfolders. However, the program seems to be really slow.
There are 50,000 .jpg pictures in this folder and subfolders. I can ...
9
votes
2
answers
300
views
Simulating surname convergence in a population
I was curious a few weeks ago about how surnames come and go (mostly on the go). I wanted to know how quickly surnames die out, because (in my simplified simulation world) once the last person with a ...
5
votes
0
answers
232
views
Speeding up the implementation of Stochastic Gradient Ascent in Python
I am implementing a time-dependent Recommender System which applies BPR (Bayesian Personalized Ranking), where Stochastic Gradient Ascent is used to learn the parameters of the model. Such that, one ...
1
vote
1
answer
1k
views
Project RoboNest - Nestable/Breakable For Loops + Basic While Loops for Robot Framework
I'm implementing things in Robot Framework that it does not support by default, including nestable For Loops and, now, While Loops. I'm looking for readability, algorithm, methodology, and/or ...
11
votes
3
answers
4k
views
Removing entries from a dictionary containing bad words
I have a dictionary with each item containing a quote in another dictionary:
...
2
votes
0
answers
874
views
Python scapy subnet mapper
This a follow-up question of Python scapy - TCP port scan of subnet
I've decided to make an all powerful subnet mapper in Scapy to better understand how tools like ...
2
votes
1
answer
9k
views
Computing the powerset of a list
I've written the following code for computing the powerset of a list (we consider the list has all distinct elements, although it doesn't really matter).
Can this function be further optimized?
<...
3
votes
2
answers
4k
views
Calculate True Positive, False Positive, True Negative and False negative and colourize output
Objective : Calculate True Positive, False Positive, True Negative and False negative and colourize the image accordignly, based on ground-truth and prediction from my classifier model.
Problem : ...
1
vote
2
answers
1k
views
Find count of alternating numbers
What I am trying to do is to find count of alternating numbers such that it alternates with -ve and positive sign for e.g.: 1 -2 3 -4 would get me 4 3 2 1 as from 1 to -4 including the two numbers ...
1
vote
2
answers
472
views
Read n lines, and count the lines that do not contain the string "CD"
I would like to know how to improve the execution speed of the code below.
The context : n is an integer read from the stdin, and represents the number of cases. Each case is represented by a ...
3
votes
2
answers
730
views
Merging the frequency rankings of boys' names and girls' names
Problem statement:
The html pages for each year which represents the top 1000 most common Girl and Boy names in the order of their frequency are ranked and provided. And they are ranked based on the ...
8
votes
3
answers
2k
views
Replacing English words in a string with their Spanish equivalents by dictionary lookup
I want to improve my code's performance and running time, looking for write my loops better.
For example, I have a dictionary that contains words as keys, and their translation in Spanish as values.
...
3
votes
5
answers
132
views
Product iteration while checking for overlaps
This is an extended question to the following question I posted
Class scheduling tool with image output
Context of previous question:
I have a multilayered dictionary that contains information ...
6
votes
3
answers
284
views
Class scheduling tool with image output
I have a multilayered dictionary that contains information about classes. I am using this to code an automatic schedule builder that I will eventually add to a separate Tkinter application I made that ...
8
votes
2
answers
14k
views
Python code that compares two files byte by byte
I wrote a Python (2.7) script that compares a file byte by byte. filecmp was not suitable for the application because it compares metadata as well. How can I ...
3
votes
1
answer
2k
views
Django REST Framework - PDF Generator
I created a new endpoint for an API (Django REST Framework) that generates a PDF from an HTML template. I follow the example from the plugin django-easy-pdf.
It's working, but I would like to improve ...
8
votes
1
answer
401
views
Kernel Convolution in Python 2.7
The code I wrote performs a mean blur on an image (I hardcoded it as zebra.jpg for testing purposes).
My problem is that for an image of 39KB image it take minutes to perform, is there any way of ...
3
votes
1
answer
3k
views
Select value based on condition on dataframe
I have some data in data frame and would like to return a value based on specific conditions. It is highly time consuming.
I tried three methods:
Method 1:
Without dataframe, this is the simple ...
3
votes
1
answer
221
views
Python CGI front-end for web service to perform machine translation
I am trying to optimize this python script that is used to process web requests for machine translation. The actual translation executable that is called is quite fast. Also, the perl scripts that are ...
1
vote
1
answer
537
views
Drawing pixel to pixel
I'm drawing a pixel by pixel image with the following code:
...
4
votes
4
answers
21k
views
Use Python to determine the repeating pattern in a string
I am writing an algorithm to count the number of times a substring repeats itself. The string is between 1-200 characters ranging from letters a-z. There should be no left overs at the end of the ...
1
vote
1
answer
840
views
Counting and scoring two- and three-word phrases
I am writing a function to take a list of words and score 2 and 3 word phrases based on occurrence while removing any phrase occurrences with a score of less than 3.
As someone kinda new to python, i'...
4
votes
2
answers
997
views
Loop through database and run shell commands with Python and exiftool
Briefly, I'm looking at getting the code below to execute faster. I have 100k images to go through. I'm running a query against MySQL, looping through results and then running exiftool against an ...
4
votes
1
answer
2k
views
Student Attendance Record II
I'm currently working on the Student Attendance Record II problem:
Given a positive integer \$n\$, return the number of all possible
attendance records with length \$n\$, which will be regarded ...
3
votes
2
answers
4k
views
Hackerrank Submission Optimisation for Melodious Password
Given question from Hackerrank:
a password consists of exactly n lowercase English letters.
the password is melodious, meaning that consonants can only be next to
...
6
votes
1
answer
223
views
Improving the performance of a webscraper
I have here a modified version of a web scraping code I wrote some weeks back. With some help from this forum, this modified version is faster (at 4secs per iteration) than the earlier version. ...
4
votes
2
answers
714
views
Generate a Bitcoin Address and the Wif from a phrase
Is there a way to speed up my Python code?
...