Labels

Friday, August 28, 2020

Image viewer feh

feh is a light-weight, configurable and versatile image viewer.

It is very small, and good for your disk.

Example:

feh -Z -x. file_name.png

vi .bashrc and add

alias feh='feh -Z -x.'


Reference:

https://man.finalrewind.org/1/feh/

Interactive with matplotlib figure

The interaction with the figure is very important.
Some keyboard shortcuts are helpful.

e.g.
After zoom the figure, you can press 'r' or 'h' to recover to default size.
'f' can show the figure in fullscreen.




Reference:

Thursday, August 27, 2020

Scipy optimize error "length of x0 != length of bounds"

 

from scipy.optimize import minimize
def fun(x):
    return x-1
minimize(fun, [2],bounds = ((0,4)))
It will raise "ValueError: length of x0 != length of bounds". We should change ((0,4)) to ((0,4),)
minimize(fun, [2], bounds=((0, 4),))
Reference: https://github.com/scipy/scipy/issues/9692#issuecomment-455258618

Tuesday, August 25, 2020

Compute Jacobian matrix by Sympy

Computing the Jacobian matrix is not easy, but we can use the python symbolical package Sympy to get it.

Here is a simple example.

import sympy as sym
from sysmpy import init_printing
from sympy import sin,cos,Matrix

init_printing()

x,y=sym.symbols('x y')
F=Matrix([x*cos(y),x*sin(y),x**2])
X=Matrix([x,y])
print(F.jacobian(X))
print(F.jacbian(X).subs([(x,0),(y,1)]))



Reference:
https://docs.sympy.org/latest/modules/matrices/matrices.html
https://www.sympy.org/scipy-2017-codegen-tutorial/notebooks/20-ordinary-differential-equations.html