常见函数说明
用途:打亂序列的順序
用法:numpy.random.shuffle([list,iterable]),返回值為None,直接更改列表的順序
樣例:np.random.shuffle(參數(shù))->np.random.shuffle([1,2,3])
注意:如果參數(shù)是二維的數(shù)據(jù),則只在第一維度上更改順序
用途:用于交換不同維度的值
用法:tensorflow.transpose(input, [dimension1 , dimension2 , dimension3 ...])
樣例:new_matrix = tensorflow.transpose(np.arange(20).reshape(5,-1), [1,0])->實(shí)現(xiàn)了轉(zhuǎn)置
用途:切割張量
用法:tensorflow.split(value, num_or_size_splits, axis=0)
兩種切割: 以一個(gè)20 * 30 * 40的張量my_tensor為例
- 如果num_or_size_splits傳入的是一個(gè)整數(shù),這個(gè)整數(shù)代表這個(gè)張量最后會(huì)被切成幾個(gè)小張量。此時(shí),傳入axis的數(shù)值就代表切割哪個(gè)維度(從0開始計(jì)數(shù))調(diào)用tf.split(my_tensor, 2,0)返回兩個(gè)10 * 30 * 40的小張量。
- 如果num_or_size_splits傳入的是一個(gè)向量,那么向量有幾個(gè)分量就分成幾份,切割的維度還是由axis決定。比如調(diào)用tf.split(my_tensor, [10, 5, 25], 2),則返回三個(gè)張量分別大小為 20 * 30 * 10、20 * 30 * 5、20 * 30 * 25。很顯然,傳入的這個(gè)向量各個(gè)分量加和必須等于axis所指示原張量維度的大小 (10 + 5 + 25 = 40)。
用途:以一定的概率選擇元素
用法:np.random.choice(a, size, replace=True, p=None)
???從0~a-1中選擇元素,size可以為多維,replace為True表示可以重復(fù)選擇元素,p代表每個(gè)元素的概率,默認(rèn)相等
示例:import numpy as np a1 = np.random.choice(a=5, size=3, replace=False, p=None) print(a1) a2 = np.random.choice(a=5, size=3, replace=False, p=[0.2, 0.1, 0.3, 0.4, 0.0]) #非一致的分布,會(huì)以多少的概率提出來 print(a2)
5. np.random.rand
用途:生成一個(gè)在0~1之間均勻分布的隨機(jī)數(shù),
用法:np.random.rand(shape)
6. zipfile.ZipFile.namelist()
用途:讀取壓縮文件的文件列表
用法: with zipfile.ZipFile(filename.zip) as f:print(f.namelist()) # 輸出該壓縮文件里的文件列表
7. tf.compat.as_str()
用途:實(shí)現(xiàn)python2和python3對字符串處理的兼容性,將bytes或者Unicode的字符串都轉(zhuǎn)換為unicode字符串
用法:tf.compat.as_str(bytes_or_text, encoding='utf-8')
8. array.argsort()
用途:按照數(shù)組內(nèi)的元素從小到大排序,并返回其對應(yīng)元素在原數(shù)組的索引列表
用法:
9.python的map()函數(shù)——map(function , iterable)
用途:第一個(gè)參數(shù) function 以參數(shù)序列中的每一個(gè)元素調(diào)用 function 函數(shù),返回包含每次 function 函數(shù)返回值的新列表。
用法:
參考
https://blog.csdn.net/jasonzzj/article/details/53932645
https://blog.csdn.net/uestc_c2_403/article/details/73350498
https://blog.csdn.net/SangrealLilith/article/details/80272346
https://blog.csdn.net/qfpkzheng/article/details/79061601
https://blog.csdn.net/heifan2014/article/details/78953574
https://www.cnblogs.com/alummox/p/7414279.html
https://stackoverflow.com/questions/37689802/what-is-tensorflow-compat-as-str
https://www.cnblogs.com/yyxf1413/p/6253995.html
http://www.runoob.com/python/python-func-map.html
總結(jié)
- 上一篇: 向量空间模型(Vector Space
- 下一篇: 【C++】 vector.erase()