Kill a python process
ps a to get the PID of your process. kill -9 <pid> to send it the unblockable SIGKILL signal. Note that I only have a Linux box in front of me to test, so the OS X commands may be slightly different.
ps a to get the PID of your process. kill -9 <pid> to send it the unblockable SIGKILL signal. Note that I only have a Linux box in front of me to test, so the OS X commands may be slightly different.
Using /= and *= allows you to eliminate an intermediate temporary array, thus saving some memory. Multiplication is less expensive than division, so is marginally faster than Since we are using basic numpy methods here, I think this is about as efficient a solution in numpy as can be. In-place operations do not change the … Read more
Well that is because according to the python doc Tuples are constructed by the comma operator (not within square brackets), with or without enclosing parentheses, but an empty tuple must have the enclosing parentheses, such as a, b, c or (). A single item tuple must have a trailing comma, such as (d,). so if … Read more
_ has 3 main conventional uses in Python: To hold the result of the last executed expression in an interactive interpreter session (see docs). This precedent was set by the standard CPython interpreter, and other interpreters have followed suit For translation lookup in i18n (see the gettext documentation for example), as in code like raise … Read more
I have a python dictionary that looks like this: They keys are type int, the values are type float64. Unfortunately, when I try to plot this with lines, matplotlib connects the wrong points (plot attached). How can I make it connect lines in order of the key values?
Personally I can’t convince myself to litter my code with the markers. I’ve become pretty used to (and efficient) at using indent-folding. Together with my mapping of space bar (see below) to open/close folds and the zR and zM commands, I’m right at home. Perfect for Python!
This gets the first item from the list that matches the condition, and returns None if no item matches. It’s my preferred single-expression form. However, The naive loop-break version, is perfectly Pythonic — it’s concise, clear, and efficient. To make it match the behavior of the one-liner: This will assign None to x if you … Read more
You can use: Or with ax=0 the average is performed along the row, for each column, returning an array with ax=1 the average is performed along the column, for each row, returning an array with ax=None the average is performed element-wise along the array, returning a scalar value
I am trying to create a 16-bit image like so: But I get the error TypeError: Image data can not convert to float.
In Python 3 use input(): In Python 2 use raw_input(): This only waits for the user to press enter though. One might want to use msvcrt ((Windows/DOS only) The msvcrt module gives you access to a number of functions in the Microsoft Visual C/C++ Runtime Library (MSVCRT)): This should wait for a key press. Additional … Read more