Featured image of post Python Snippet

Bash Snippet

Python Snippet

Basic

未定長度函數參數

1
2
3
def f(*a):
	for i in range(len(a)):
		print(i, a[i])

polynomal

1
2
3
4
5
6
7
8
# polynomial(2, 4, 6, 8)(x) -> 2x^0 + 4x^1 + 6x^2 + 8x^3
def polynomial(*ai):
    def f(x):
        r = 0
        for n, a in enumerate(ai):
            r += a*x**n
        return r
    return f

Type Annotation

Numpy Array as Parameter

1
def func(A: np.ndarray)

stackoverflow

Numpy

Determinant of array

1
np.linalg.det(A)

doc

Multiply a Matrix and a Array

1
np.dot(A, x)

stackoverflow

好想養貓阿~~
使用 Hugo 建立
主題 StackJimmy 設計