Jupiter
Install
sudo pip install -U pip setuptools
sudo pip install jupyter # Install package from name
sudo pip install *.whl # Install package from local WHL distribution (Python wheel packaging standard)
Usage/Activation
jupyter notebook # start web-server and open web-client
jupyter notebook --ip 0.0.0.0 --port 8888 # start web-server and allow connection from outside (incoming connection from all network interfaces will be accepted)
ipython # open console based client
*.ipynb # python notebook files extention
Cells roughly speaking can be of two types:
Code
Markdown
Working in a web-based interface
Conda and Pip package managers
Conda has two goals:
1. Conda is a package manager.
2. Conda is an environment manager. Each project can have a specific requirement in a specific version of the library.
To install Conda there are two ways:
1. Anaconda distribution contains Conda and another thing.
2. Install Miniconda (https://docs.conda.io/en/latest/miniconda.html)
Package manager commands
Environment manager commands
Conda cheatsheet
Conda documentation by the tasks
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/index.html
References:
[1] https://pythonprogramming.net/introduction-and-basics-cython-tutorial/#cdef-declarations
[3] https://cython.readthedocs.io/en/latest/index.html
#1 step is to have the usual python file "*.py" and change extension to "*.pyx"
#2 step one powerful thing that can be used now during using Cython you can append type information.
cdef int x,y,z
cdef char *s
cdef float x = 5.2 (single precision)
cdef double x = 40.5 (double precision)
cdef list languages
cdef dict abc_dict
cdef object thing
It brings very-very big speedup immediately!
#3 step you can append extra modifiers to functions
def - regular python function , calls from Python only (as it were even without using Cython)
cdef - cython only functions, can't access these from python-only code, must access within Cython
cpdef - C and Python. Will create a C function and a wrapper for Python.
Why not *always* use cpdef? In some cases, you might have C only pointer, like a C array.
#4 step. Script to build all *.pyx files in current directory
#!/usr/bin/env python
# build.py - cythonize all *.pyx filesfrom distutils.core import setup from Cython.Build import cythonize setup(ext_modules = cythonize('*.pyx'))
#5 step. Script to launch the previous script
#!/usr/bin/env bashpython build.py build_ext --inplace
#6 step. Use build cython module from Python
import mylib
Another notes on the subject: https://sites.google.com/site/burlachenkok/articles/cython
#7 step. Measure execution time
def timing(f): def wrap(*args): time1 = time.time() ret = f(*args) time2 = time.time() print('{:s} function took {:.3f} ms'.format(f.__name__, (time2-time1)*1000.0)) return ret return wrap @timing def vector_add_naive(a, b, c): for i in range(len(c)): c[i] = a[i] + b[i]
Launch Python web-server to share files from current directory
# Python 2 python -m SimpleHTTPServer # Python 3 python -m http.server