Skip to content

Instantly share code, notes, and snippets.

@cjue25
cjue25 / 01_read.py
Last active February 27, 2021 11:54
Using Python for Research_Case Study 1 &2
def read_seq(inputfile):
"""reads and returns the imput sequence with special characters removed."""
with open(inputfile, 'r') as f:
seq=f.read()
seq = seq.replace("\n","")
seq= seq.replace("\r","")
return seq
@cjue25
cjue25 / 01_statsmodels.api.py
Last active February 8, 2018 09:42
Using Python for Research_Case Study 7
import statsmodels.api as sm
mod=sm.OLS(y, x) #ordinary least sqares
est=mod.fit()
print (est.summary())
#這裡得出來的斜率較大是因為沒有截距,從0開始畫
#可以print 出詳細資訊
X=sm.add_constant(x)
mod=sm.OLS(y, X)
@cjue25
cjue25 / 01_Basics_of_NetworkX.py
Last active February 8, 2018 08:47
Using Python for Research_Case Study 6
#Basics of NetworkX
import networkx as nx
G=nx.Graph()
#增加節點
G.add_node(1)
#一次增加多個節點
G.add_nodes_from([2,3,'u','v'])
@cjue25
cjue25 / 00_notes.txt
Last active February 7, 2018 19:54
Using Python for Research_Case Study 5
"""
np.isnan()
查看是否有nan
np.isnan(speed).any()
是true的話代表一定有nan值
np.sum(np.isnan())
看有幾個nan的值
@cjue25
cjue25 / 00_notes.txt
Last active February 5, 2018 19:01
Use Python for Research_edX_Case_Study_4
運用的觀念
pearson correlation
spectral co-clustering
adjacency matrix
eigenvalues eigenvectors
bokeh用法
@cjue25
cjue25 / 00_notes.txt
Last active February 4, 2018 16:30
Use Python for Research_edX_Case_Study_3
numpy.power(兩點相減,相差的平方)
max(dictionary) = max(dictionary.keys())
max(dictionary.values()) 是找值
scipy.stats.mstats.mode
直接丟入list( or array),可以轉換成(最多出現的值,次數)
但是呈現規則為「次數皆相同者,只會秀出最小的值」,沒有考慮重複的問題
np.argsort(np.array) #從給定的np.array中由小排到大的index位置