Table of Contents
See also my original webpage
Use the logger utility in your Python code to track and save your running to log file easily.
Code | Example |
---|---|
logger | example |
We have created a Python package for the ease use of this logger - Link.
If you installed a module by pip, you may cannot load it.
To be sure you install the package using the correct pip instance for your python interpreter you need to run something like:
/bin/env python -m pip install --upgrade mymodule
or for OSX
/usr/bin/env python -m pip install --upgrade mymodule
try the following ones
plt.rc('xtick', labelsize=15)
plt.rc('ytick', labelsize=15)
plt.tick_params(axis='both', which='major', labelsize=15)
cbar = plt.colorbar(im, cax=cax)
cbar.ax.tick_params(axis='both', which='major', labelsize=15)
plt.rcParams.update({'font.size': 15})
try the following two ways
plt.xlabel('a', fontsize=15)
plt.ylabel('b', fontsize=15)
or
ax = plt.subplot(111)
ax.set_xlabel('x', fontsize=15)
ax.set_ylabel('y', fontsize=15)
plt.xticks(rotation = 90)
>>> a = np.array([[1,2,3], [4,5,np.nan], [7,8,9]])
array([[ 1., 2., 3.],
[ 4., 5., nan],
[ 7., 8., 9.]])
>>> a[~np.isnan(a).any(axis=1)]
array([[ 1., 2., 3.],
[ 7., 8., 9.]])
import numpy as np
import random
seed = 12345
np.random.seed(seed)
random.seed(seed)
Anaconda is a very good python package including all useful scientific computing tools. It can be downloaded from: link
run the following command:
>bash Anaconda-2.x.x-Linux-x86[_64].sh
In order to have autocompletion using TAB in the terminal, we have to load two commands:
import rlcompleter, readline
readline.parse_and_bind('tab:complete')
Those two lines can be automatically loaded by creating a .pythonrc in your home directory with those two files and by adding
export PYTHONSTARTUP=~/.pythonrc
to your .profile
>python -m pdb <your_code.py>
At start you are at the begining of your code. Then you can create breakpoints.
- Breakpoint at line 100 in the main file:
(Pdb) b 100
- Breakpoint at line 50 in another file:
(Pdb) b myclass.py:50
You can go though your code until first breakpoint by typing 'c' (continue)
You can go though your code step by step:
- n: execute current statement
- s: execute and step into
Enable/Disable/Clear breakpoint:
- disable number
- enable number
- clear number
(Pdb) b myclass.py:50
- Breaking on error:
>python -Werror -mpdb <your_code>
>python -m cProfile <your_code.py>
Matlab | Python/Numpy |
---|---|
X[1] (indexing starts at 1) | X[0] (indexing starts at 0) |
Automatically generate table of content: generated with DocToc