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 35351

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

3 votes
1 answer
1k views

Workaround for the precision limitation for Python's round() function

I'm trying to come up with a general way to correctly round floats with Python, given the known limitation of round(): Note: The behavior of round() for floats can be surprising: for example, round …
Gabriel's user avatar
  • 597
4 votes

Workaround for the precision limitation for Python's round() function

Following ferada's advice I looked up the decimal module and it simplifies things quite a bit. This is a function that does what format_5() does but much succinctly: def format_5_dec(f): new_flo …
Gabriel's user avatar
  • 597
1 vote
1 answer
2k views

Mean of combined sublists with different lengths

I have a seemingly simple issue. Consider this list: a = [[12.0, 5.0, 63.0], [0.1, 2.0, 7.1, 3.0, 2.3, 5.0, 8.4]] I want to find the mean (using numpy) of all the elements in its sublists combined. …
Gabriel's user avatar
  • 597
2 votes
1 answer
2k views

Getting information from URL efficiently

I'm running python 2.7.3. …
Gabriel's user avatar
  • 597
5 votes
1 answer
94 views

Increase performance of Bayesian likelihood equation

I need to calculate a Bayesian likelihood in its negative logarithmic form: $$-\ln L = N\ln M -\sum\limits_{i=1}^{N} \ln\left\{P_i \sum\limits_{j=1}^M \frac{\exp\left[ -\frac{1}{2}\left(\sum_{k=1}^D …
Gabriel's user avatar
  • 597
7 votes
1 answer
7k views

Obtaining prediction bands for regression model

I'm trying to generate prediction bands for an exponential fit to some 2-dimensional data (available here). The data (blue points), best fit found by scipy.optimize.curve_fit (red curve), and lower & …
Gabriel's user avatar
  • 597
3 votes
1 answer
3k views

Coordinates of 2D points zoomed in/out

This might be a simple issue that I am overcomplicating, but I've spent quite some time reading about polygon scaling and I've come to the conclusion that it is not precisely what I need. Given a set …
Gabriel's user avatar
  • 597
2 votes
1 answer
193 views

Neural network text classifier

I wrote a simple NN text classifier to help me quickly sort through the new daily submissions to the arXiv. It downloads the new submissions, processings their titles and abstracts, trains a NN on so …
Gabriel's user avatar
  • 597
10 votes
2 answers
209 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 …
Gabriel's user avatar
  • 597
4 votes
0 answers
97 views

Estimate area of cropped circle with Monte Carlo

I looking around and not finding anything, I developed a simple function for estimating the area of a possibly cropped circle inside a frame. It uses a very basic MC implementation. It is pretty fast …
Gabriel's user avatar
  • 597
6 votes
1 answer
3k views

Improve performance of Gaussian kernel function evaluation

I need to improve the performance of a function that calculates the integral of a two-dimensional kernel density estimate (obtained using the function stats.gaussian_kde) where the domain of integrati …
Gabriel's user avatar
  • 597
0 votes
2 answers
171 views

Faster generation of list with multiple sublists [closed]

I'm trying to improve the performance of some rather large code. One of the bottlenecks is the line below. It doesn't look like much but it is processed millions of times. Is there any way to improve …
Gabriel's user avatar
  • 597