threshold in 2D numpy array

One solution: The first part array < 25 gives you an array of the same shape that is 1 (True) where values are less than 25 and 0 (False) otherwise. Element-wise multiplication with the original array retains the values that are smaller than 25 and sets the rest to 0. This does not change the … Read more

Superscript in Python plots

You just need to have the full expression inside the $. Basically, you need “meters $10^1$”. You don’t need usetex=True to do this (or most any mathematical formula). You may also want to use a raw string (e.g. r”\t”, vs “\t”) to avoid problems with things like \n, \a, \b, \t, \f, etc. For example: … Read more

How do I add two sets?

All you have to do to combine them is Sets are unordered sequences of unique values. a | b or a.union(b) is the union of the two sets (a new set with all values found in either set). This is a class of operation called a “set operation”, which Python sets provide convenient tools for.

Trying to run Flask app gives “Address already in use”

It means there’s another service’s using that port (8080 in this case). Maybe because you forgot close another running Flask app and it’s using 8080 port. However, you could change the port you’re using, for example change it to 4444 like this: But anyways, I think you’d like to know which program is using that … Read more

Python official installer missing python27.dll

At least for the ActiveState Python distribution, and in the official Python distribution: The dll is in where NN is the version number. On a 64-bit, a 32 bit dll will be installed here: and a running 32 bit application will magically translate this to the proper path, http://en.wikipedia.org/wiki/WoW64 When I link againsy Python27, I … Read more