What do the python file extensions, .pyc .pyd .pyo stand for?

.py: This is normally the input source code that you’ve written. .pyc: This is the compiled bytecode. If you import a module, python will build a *.pyc file that contains the bytecode to make importing it again later easier (and faster). .pyo: This was a file format used before Python 3.5 for *.pyc files that were created with optimizations … Read more

How do I print the key-value pairs of a dictionary in python

Python 2 and Python 3 i is the key, so you would just need to use it: Python 3 d.items() returns the iterator; to get a list, you need to pass the iterator to list() yourself. Python 2 You can get an iterator that contains both keys and values. d.items() returns a list of (key, value) tuples, while d.iteritems() returns an iterator that provides … Read more

How do I remove/delete a virtualenv?

“The only way I can remove it seems to be: sudo rm -rf venv“ That’s it! There is no command for deleting your virtual environment. Simply deactivate it and rid your application of its artifacts by recursively removing it. Note that this is the same regardless of what kind of virtual environment you are using. virtualenv, venv, Anaconda … Read more

Moving average or running mean

UPDATE: more efficient solutions have been proposed, uniform_filter1d from scipy being probably the best among the “standard” 3rd-party libraries, and some newer or specialized libraries are available too. You can use np.convolve for that: Explanation The running mean is a case of the mathematical operation of convolution. For the running mean, you slide a window along the input and compute the mean of … Read more