python 中好用的函數,random.sample等,持續更新
random.sample
random.sample的函數原型為:random.sample(sequence, k),從指定序列中隨機獲取指定長度的片斷。sample函數不會修改原有序列
import random list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] slice = random.sample(list, 5) # 從list中隨機獲取5個元素,作為一個片斷返回 print(slice) print(list)# 原有序列並沒有改變 [1, 8, 7, 6, 4] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
seaborn tsplot
Pandas的DataFrame常常和tsplot搭配使用,DataFrame的用法以及構造數組的具體例子參考博客。
最簡單的時序折線圖繪制見參考例子。更多關於參數unit,direction,time的使用暫時還沒有弄明白,后續補充。
和plot相比最大的好處就是可以畫出平均線,比如對比兩種方法的性能,每一種方法有100條結果,用tsplot可以直觀對比平均線。
tensorflow.python.platform flags 標志的使用
學習參考鏈接:tensorflow命令行參數原理詳細解析以及實例。
python assert的作用
學習參考鏈接:python assert的作用、簡單的例子。
python dir(對象)
dir()
是一個內置函數,用於列出對象的所有屬性及方法。
reuse_variables()的用法
參考莫凡python,以及下列示意性代碼
with tf.variable_scope('model', reuse=None) as training_scope: print(dir(self)) if 'weights' in dir(self): training_scope.reuse_variables() weights = self.weights else: # Define the weights self.weights = weights = self.construct_weights()
tf.assign()、tf.assign_add()的用法