Tagged Questions
4
votes
1answer
47 views
Product of corresponding elements in 2 arrays
Given two arrays A and B, of length N and length k ...
3
votes
0answers
48 views
Python Multiprocessing: Using mutable ctype arrays seems to work, yet I am not seeing significant speed-up. Why?
As a brief introduction, I am student working on a body of code which forms part of my Masters' research - this is my first question on SO. My background is in physics and mathematics, so I will ...
5
votes
2answers
44 views
Finding the best matching block/patch in Python
I wish to locate the closest matching NxN block within a WxW window centred at location (x,y) of a larger 2D array. The code below works fine but is very slow for my needs as I need to run this ...
3
votes
2answers
867 views
Find and process duplicates in list of lists
I'm trying to merge counts for items (URLs) in the list:
[['foo',1], ['bar',3],['foo',4]]
I came up with a function, but it's slow when I run it with 50k ...
7
votes
6answers
558 views
Python address index +1 with list comprehension
Task from CodingBat:
Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after ...
2
votes
0answers
64 views
Optimization Algorithm: Too much memory consumed
What I have here is an implementation of an optimization algorithm called the covariance matrix adaptation evolutionary strategy. I am using this algorithm to optimize the position of wind turbines ...
5
votes
3answers
189 views
Is there a simpler way to find winners when there is a tie?
Background:
I have a Python script which parses a complicated CSV generated on election nights. Each row of the CSV represents a race. As I loop through the races, I store the candidates for each ...
4
votes
2answers
613 views
Splitting an array of numbers into all possible combinations
This takes an array of numbers then splits it into all possible combinations of the number array of size 4 then in another array puts the leftovers. As I want to take the difference in averages of ...
5
votes
1answer
135 views
Optimize Cython code with np.ndarray contained
Can someone help me further optimize the following Cython code snippets? Specifically, a and b are ...
5
votes
1answer
8k views
Snake game — made with Python
I wrote a simple Python snake game, it's about 250 lines of code. Can someone give me some advice on how to refactor/make it better?
game.py
# game.py - 3/22/2013
...
10
votes
2answers
114 views
Improve performance of math function applied to arrays
This block of code is already somewhat optimized thanks to some answers given over at Stack Overflow. In the last question I made (Improve performance of function without parallelization) the code was ...
4
votes
1answer
95 views
How to make this lingo game more compact?
I made a lingo game using Python:
You guess a word, and if its letter(s) is in the same spot as a hidden word's, you add [] around the letter. If it's in the hidden word, but not in the same spot, ...
4
votes
2answers
3k views
Fastest way to iterate over Numpy array
I wrote a function to calculate the gamma coefficient of a clustering. The bottleneck is the comparison of values from dist_withing to ...
2
votes
1answer
25 views
Handling objects and arrays simply in this tagging library
I have written this little tagging module to make it easier to generate small html snippets on the fly. The examples below show how this make things a bit easier. My question is about the handling of ...
1
vote
1answer
124 views
Reading Multidimensional arrays
I am building a cypher program which uses a matrix of numbers and letters. A message is encoded according to the row an collum each letter of the message is found in the matrix.
I am trying to find a ...
4
votes
2answers
125 views
Why is this program for extracting IDs from a file so slow?
This is roughly what my data file looks like:
...
3
votes
5answers
375 views
count all array[index] == index occurrences
The method foo gets a sorted list with different numbers as a parameter and returns the count of all the occurrences such that: ...
3
votes
0answers
54 views
Summing 2D NumPy array by multiple lables
Each element of the array is a coordinate (x, y).
Each coordinate has two labels.
Goal: sum the elements that have the same two labels.
How can this be faster?
...
2
votes
1answer
97 views
What would be the optimal way to address these arrays
I think the arrays here are slowing down my code due to incorrect usage.
There is a lot of stuff going on here, it's understandable if nobody responds. Just looking for some pointers. Thanks.
...
4
votes
1answer
240 views
Optimizing Python / Numpy Code
So I'm implementing a version of the mean shift image processing algorithm for color segmentation in python/numpy.
I've written a pure numpy version of the actual mean shifting per pixel (which I ...
3
votes
4answers
264 views
How make array search more efficient in python?
Here is Python code written to perform the following operations:
Find each occurrence of a three-letter sequence in a character array (e.g. a sequence such as ...
5
votes
1answer
159 views
Sparse Bitarray Class in Python (or rather frequently having contiguous elements with the same value)
Sparse is probably the wrong word - this is for encoding arrays of booleans where contiguous values tend to be the same. It'd be great to know a proper name for this data structure so I could read ...
1
vote
1answer
133 views
What specific optimizations can be made to this BitArray class, and how can they be implemented?
Here is the current code for the BitArray class needing optimization (implemented on big integers):
...
1
vote
2answers
460 views
Python: optimize this rolling loop
I have a numpy array of about 2500 data points. This function is called on a rolling basis where 363 data points is passed at a time.
...
1
vote
3answers
763 views
Multiline Input into Python Arrays
I've knocked together a few lines of python to read in stats for a service (haproxy), and store them in an array (to do some analysis on later). It basically takes a multiline output, and splits it ...