Git的基本使用
參考來源:
http://gogojimmy.net/2012/01/17/how-to-use-git-1-git-basic/
建立 git user name & email
1 2 |
gitconfig --global user.name "your name" git config --global user.email "your email" |
改顏色
1 |
gitconfig --global color.ui true |
1 |
git clone "https://github.com/mauriceHsiao/untitled2.git" |
查看 git 狀態
1 |
git status |
(紅色字是第一階段)
1 |
gita dd . |
把資料add上去
再去看git狀態
(綠色是第二階段)
最後
1 |
gitcommit -v -m "備註" |
就可以成功commit上去
最後查看git狀態
可去查看紀錄
1 |
git log |
可開啟gui介面
1 |
gitk --all |
看到有哪些 branch
1 |
git branch |
新增 cat branch
1 |
git branch cat |
切換至cat branch
1 |
git checkout cat |
切換至 cat後,去修改檔案
查看 git狀態,知道有東西被修改
1 2 |
git add . git commit -v -m "cat test" |
commit上去
在cat上看 git log看到 cat test有被commit上去
將某一支 branch 基於另一支 branch 的內容合併起來
1 |
git rebase master |
看 cat與master的差異
1 |
git diff cat master |
切換至 master
1 |
git checkout master |
將cat所修改的內容 merge到 master
1 |
git merge cat |
所以就可以用 git log 看到 cat test 已經被 merge至 master上
Github:
https://github.com/mauriceHsiao/untitled2/blob/master/0330.py
1 2 3 4 |
#coding: utf-8 from __future__ import division A = [[1, 2, 3], [4, 5, 6]] B = [[1, 2], [3, 4], [5, 6]] |
1 2 3 4 5 |
print "---矩陣---" def shape(A): num_rows = len(A) num_cols = len(A[0]) if A else 0 return num_rows, num_cols |
1 2 |
defget_row(A, i): return A[i] |
1 2 3 4 5 |
defget_column(A, j): return [A_i[j] for A_i in A] >print shape(A) print get_row(A,0) print get_column(A,1) |
1 2 3 4 5 6 7 |
print "---矩陣---" def make_matrix(num_rows, num_cols, entry_fn): return [[entry_fn(i, j) for j in range(num_cols)] for i in range(num_rows)] defmyfun(i,j): return i * j print make_matrix(3,5,myfun) |
1 2 3 4 5 |
print "---對角矩陣---" defis_diagonal(i, j): return 1 if i == j else 0 identity_matrix = make_matrix(5, 5, is_diagonal) print identity_matrix |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
print "---5號朋友有哪些---" friendships = [[0, 1, 1, 0, 0, 0, 0, 0, 0, 0], # user 0 [1, 0, 1, 1, 0, 0, 0, 0, 0, 0], # user 1 [1, 1, 0, 1, 0, 0, 0, 0, 0, 0], # user 2 [0, 1, 1, 0, 1, 0, 0, 0, 0, 0], # user 3 [0, 0, 0, 1, 0, 1, 0, 0, 0, 0], # user 4 [0, 0, 0, 0, 1, 0, 1, 1, 0, 0], # user 5 [0, 0, 0, 0, 0, 1, 0, 0, 1, 0], # user 6 [0, 0, 0, 0, 0, 1, 0, 0, 1, 0], # user 7 [0, 0, 0, 0, 0, 0, 1, 1, 0, 1], # user 8 [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]] # user 9 friends_of_five = [i for i, is_friend in enumerate(friendships[5]) if is_friend] print friends_of_five |
1 2 3 4 5 6 7 8 9 10 11 |
print "---兩矩陣相加---" A1 = [[1, 2, 3], [4, 5, 6]] B2 = [[7,8,9],[10,11,12]] defmatrix_add(A, B): if shape(A) != shape(B): raise ArithmeticError("cannot add matrices with different shapes") num_rows, num_cols = shape(A) defentry_fn(i, j): return A[i][j] + B[i][j] return make_matrix(num_rows, num_cols, entry_fn) print matrix_add(A1,B2) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
print "---兩矩陣繪圖---" defdot(v, w): return sum(v_i * w_i for v_i, w_i in zip(v, w)) defscalar_multiply(c, v): return [c * v_i for v_i in v] defmake_graph_dot_product_as_vector_projection(plt): v = [2, 1] w = [math.sqrt(.25), math.sqrt(.75)] c = dot(v, w) vonw = scalar_multiply(c, w) o = [0, 0] plt.arrow(0, 0, v[0], v[1], width=0.002, head_width=.1, length_includes_head=True) plt.annotate("v", v, xytext=[v[0] + 0.1, v[1]]) plt.arrow(0, 0, w[0], w[1], width=0.002, head_width=.1, length_includes_head=True) plt.annotate("w", w, xytext=[w[0] - 0.1, w[1]]) plt.arrow(0, 0, vonw[0], vonw[1], length_includes_head=True) plt.annotate(u"(vâ¢w)w", vonw, xytext=[vonw[0] - 0.1, vonw[1] + 0.1]) plt.arrow(v[0], v[1], vonw[0] - v[0], vonw[1] - v[1], linestyle='dotted', length_includes_head=True) plt.scatter(*zip(v, w, o), marker='.') plt.axis('equal') plt.show() print make_graph_dot_product_as_vector_projection(plt) |
1 2 3 4 5 6 7 8 9 10 |
print "---ch04課堂報告---" print "---矩陣相加---" x = [1,2,3] y = [4,5,6] print x+y import numpy as np a = np.array([1, 2, 3]) b = np.array([2, 4, 6]) print a+b |
1 2 3 4 5 6 7 |
print("---計算向量長度---") import numpy as np a=np.array([1,3,2]) b=np.array([-2,1,-1]) la=np.sqrt(a.dot(a)) lb=np.sqrt(b.dot(b)) print (la,lb) |
1 2 3 |
print("---計算cos---") cos_angle=a.dot(b)/(la*lb) print (cos_angle) |
1 2 3 |
print("---計算夾角(單位為π)---") angle=np.arccos(cos_angle) print (angle) |
1 2 3 |
angle2=angle*360/2/np.pi print("----轉換單位為角度----") print (angle2) |
1 2 3 4 |
# 第三個範例 print("----乘法運算----") print("----矩陣相乘----") import numpy as np |
1 2 3 4 5 6 7 8 9 10 |
a = np.array([[3, 4], [2, 3]]) b = np.array([[1, 2], [3, 4]]) c = np.mat([[3, 4], [2, 3]]) d = np.mat([[1, 2], [3, 4]]) e = np.dot(a, b) f = np.dot(c, d) print (a * b) print (c * d) print (e) print (f) |
1 2 3 4 5 |
# 第四個範例 print "---亂數產生---" import numpy as np a = np.random.randint(1, 10, (3, 5)) print (a) |
1 2 3 4 5 |
# 第五個範例 print "---計算矩陣行列式---" from numpy import * a = mat([[1, 2, -1], [3, 0, 1], [4, 2, 1]]) print linalg.det(a) |
1 2 3 4 5 6 7 8 |
# 第六個範例 print "---矩陣畫圖---" import numpy as np from matplotlib import pyplot x = np.arange(0, 10, 0.1) y = np.sin(x) pyplot.plot(x, y) pyplot.show() |
備註:2017/03/30 計算方法與設計-課堂筆記