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 76662

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.

7 votes

Return True if num is within 2 of a multiple of 10

I thought MrSmith42's answers were really compact and readable. But I wanted to see if they were faster. Also, I wanted to test numpy for comparison. Here's my numpy version: def near_ten5(num_lis …
Curt F.'s user avatar
  • 1,626
3 votes

Determining if a word is an anagram of another

Inspired by MrSmith42's nice answer, I came up with a version that doesn't require sorting of the full arguments, just sorting of their Counter()s. And that sorting is triggered only if the set()s of …
Curt F.'s user avatar
  • 1,626
4 votes

Checking a word grid

Inspired by Calpratt's observation that this is really a question about testing matrix symmetry, I wanted to post a numpy version. from sys import exit from itertools import permutations import nump …
Curt F.'s user avatar
  • 1,626
4 votes

Project Euler #2 in Python

Nice work getting the problem right. Here are a few pointers: Storing the full array of Fibonacci numbers isn't necessary. You are taking the sum "as you go" and not storing every summand in the s …
Curt F.'s user avatar
  • 1,626
1 vote
Accepted

Creating a count inversion array of an unsorted array of unique integers

In Python, line-profiler is an easy to use package for assessing the performance of your code. … Using numpy for applications like this makes sense because python doesn't have a mutable fixed-type data structure. …
Curt F.'s user avatar
  • 1,626
2 votes
Accepted

Fast Python spring network solver

Starting from Jaime's solution, I noticed that np.bincount was being called in each loop iteration. This function seems to compute the mapping between links and knots, which is something that doesn't …
Curt F.'s user avatar
  • 1,626
2 votes
Accepted

Checking convergence of 2-layer neural network in python

Why are your weights Python lists instead of NumPy arrays? If you're already using NumPy, you might as well use it wherever you can. …
Curt F.'s user avatar
  • 1,626
2 votes
Accepted

Calculating doubling times from data points

Your code is doing the job, but I think there are a few ways in which it could be improved. Consistent use of parameters for functions. def doubling_time(m, x_pts, y_pts): window = 10 …
Curt F.'s user avatar
  • 1,626
2 votes

Particle swarm optimization - follow-up

I'm not experienced enough at OOP to give you meaningful feedback on your class models, but here are two quick things I noticed when scanning my novice eyes over your code: Undocumented parameters. …
Curt F.'s user avatar
  • 1,626
5 votes
Accepted

Imputing values with non-negative matrix factorization

In the while loop, the first call you make to nmf_model.fit_transform() is superfluous and can be removed. You aren't even using the results of the transformation calculation. The next line, where …
Curt F.'s user avatar
  • 1,626
4 votes
Accepted

Downloading list of images

I think this is pretty good code! I have only a few minor suggestions: Rename image and images to something that makes clear they are URLs, not files, not numpy ndarrays, and not any other format. …
Curt F.'s user avatar
  • 1,626
3 votes

NumPy array as quasi-hash table

I think this looks pretty efficient. Let me add a few more minor, detailed comments (more than 1 year after the question was asked; I hope they are still useful): After you convert to a NumPy array …
Curt F.'s user avatar
  • 1,626
3 votes
Accepted

Find binary sequence in NumPy binary array

The python convention for naming functions is snake_case i.e. all lowercase with underscores, not camelCase. So findPulseSlow should be find_pulse_slow etc. … Watch out for places where you are inadvertently causing interconversion of NumPy data types and native Python data types. For example, sum(np.logical_xor(...) should be np.sum(np.logical_xor(...) …
Curt F.'s user avatar
  • 1,626
5 votes

Army strength based on level and modifiers

All-lowercase (for functions) is good python style. You're only using one function from random, so from random import randint is better than loading in the whole module with import random. …
Curt F.'s user avatar
  • 1,626
2 votes

Dataset and frequency list generation by looping over files

Rather than having your two functions called explicitly at the bottom of the the code, the python idiom is to nest those calls under a if __name__ == "__main__": statement. … A very excellent Stack Overflow answer has more info on the if __name__ == "__main__": idiom in python. …
Curt F.'s user avatar
  • 1,626

15 30 50 per page