31
votes
Python decibel meter-accurate?
Indent your code with a PEP8-compliant IDE or linter; it's a perfect mess right now.
Move your global code into functions and maybe classes. There are two good use cases for classes here - one for a ...
10
votes
Chi Square Independence Test for Two Pandas DF columns
Using pandas.crosstab, this can be done in a single step:
pandas.crosstab(index=test_df['var1'],columns=test_df['var2'])
It ...
9
votes
Accepted
Farthest point algorithm in Python
First, a style comment. On the internet, especially in programming, and in particular on this website, English is the lingua franca. So you should avoid mixing other languages and English. This way ...
8
votes
Accepted
Fourier Series of a given function
I like it.
This code hews closely to the underlying math,
using lovely identifiers, and is very clear.
For {a,b}_k, here's the only
part I'm not super happy with:
...
7
votes
Accepted
Factorio analysis: data munging
You can simplify your 'verbose' multi-line regexes by using the re.X flag.
...
6
votes
Accepted
Epidemic simulation
78 characters of indentation at its deepest: this code is unreadable. We can't easily match the core of the code with the definition of the parameters.
To improve that, you can:
use 4 space per ...
6
votes
Simulation of spring-loaded inverted pendulum
Inspired by @Alex's answer, I did some profiling and simple timing of your code, and some changes that seemed "obvious" to me.
My environment for this is a 32-bit laptop that is old enough to have a ...
6
votes
compare between two labels /objects -dominance rules
You use a docstring to good effect. I'd think it great if you followed the rules closely:
...
5
votes
Accepted
Counts instances for each category for many Matlab files
You felt it right, there's a lot of unnecessary copy/paste in the first part.
Your 5 data structures are similar, and you create a lot of variables to perform the same processing 5 times.
I did a ...
5
votes
Accepted
Monte Carlo errors estimation routine
Before starting with feedback on the actual code, I would like to share some thoughts about the style.
Chose a style, be consistent
Python comes with an official style guide called PEP8 which ...
5
votes
Accepted
Simulation of spring-loaded inverted pendulum
Style
Your code looks quite good in general, but there is always something to nitpick on, isn't it?
Python comes with an official Style Guide, often just called PEP8. It has quite an extensive ...
5
votes
Srivastava multivariate Fox H function in MATLAB
There are some obvious inefficiencies in the code that I can point out.
The profiler shows that most time is spent doing symbolic math. You use symbolic math to compute the product of a series of ...
4
votes
ChiSquare test Code in Python
Pandas and Scipy have seen several non-backward-compatible changes since this question was posted. I will claim that even in 2016, the code should have been written to better use the Pandas API at the ...
4
votes
Accepted
Probability of event using Central Limit Theorem + plotting results
You seem to know about str.format (since you use it), yet you are still doing string addition:
...
4
votes
Accepted
2d linear Partial Differential Equation Solver using finite differences
There's no docstring for fd_solve. The post contains a description that would make a good start.
The docstring has ...
4
votes
Accepted
Calculate electric field of a charged annulus
I think the main time consuming factor here is calculating the dbquad, that said there are some smaller improvements you can make
split into functions
lookup of ...
4
votes
Accepted
Simple natural language classifier
Welcome to Code Review!
This is an interesting program; thanks for sharing!
To help you maintain it ...
baseDict appears to be unused, and can be removed. Ditto ...
4
votes
Accepted
Spearman correlations between Numpy array and every Pandas DataFrame row
Since Spearman correlation is the Pearson correlation coefficient of the ranked version of the variables, it is possible to do the following:
Replace values in df ...
4
votes
Counting Bouncy Numbers: Project Euler #113
Project Euler problems generally can be computed with a calculator or manually.
So, take a different approach:
For ascending numbers, choose the transitions (digits 0-9; 9 transitions).
For ...
4
votes
Accepted
Python Implementation of Canopy Structural Dynamic Model using scipy.optimize.least_squares
Convex optimiser
This class of problem is very sensitive to initial conditions if you aren't careful. It has significant degrees of freedom and multiple exponential terms. Your provided estimate is ...
4
votes
Accepted
Local solver built into a global one
As a start:
Do not write experimental_data_list all in one line; give each row its own line and put it into an np.array.
Combine ...
4
votes
Accepted
Matrix Factorisation class packaging methods for factorisation of explicit & implicit data matrices using Gradient Descent, SGD and ALS
imports
I don't understand why you omitted these lines.
I added them back.
They alter the meaning of the submitted source code,
and make it reviewable.
...
3
votes
Accepted
Implement metaclass for Maximumlikelihood estimator
Instead of constructing the object and then modifying its methods and attributes, you can directly add them in the __new__ method of the metaclass:
...
3
votes
Raster processing for climate change model
First, fix the bug!
You're using sys.exc_info()[-1].tb_lineno but you're not importing the sys module anywhere, so do that ...
3
votes
Multidimensional matrix exponentiation
Dig through the source code for expm, which leads ultimately to a rather extensive bit of code in scipy.sparse.linalg.matfuncs.py...
3
votes
Accepted
Polynomial curve-fitting over a large 3D data set
In terms of possible speed optimisations there's not much to work with, but one thing does stand out:
...
3
votes
Accepted
Compute Gini Coefficient
Stick closely to the sources
It's helpful when coding math in cases like this to base your approach on established methods and language.
It might seem a bit extreme, but this can include:
Following ...
3
votes
Accepted
Fast distance calculation for Starcraft2 bot
You should probably have another look at the scipy.spatial module. It provides (hopefully) faster methods for most of these checks using a k-d-tree.
...
3
votes
Double pendulum real time plot
There's a lot to like about this program:
It's relatively light on the requirements
The animation is smooth, seemingly accurate, and updates in real-time with the parameter controls
It's pretty ...
3
votes
Numerical Double Integration using numba and scipy
Prior to vectorisation, the simple version of this can look like
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scipy × 86python × 84
numpy × 38
performance × 22
python-3.x × 18
statistics × 10
numerical-methods × 10
matrix × 8
pandas × 8
python-2.x × 7
matplotlib × 6
mathematics × 5
clustering × 5
algorithm × 4
physics × 4
signal-processing × 4
object-oriented × 3
image × 3
time-limit-exceeded × 2
reinventing-the-wheel × 2
simulation × 2
machine-learning × 2
computational-geometry × 2
matlab × 2
vectorization × 2