np
from autograd import grad
grad(func) 微分
np.shape
reshape(-1,1) 重新排列,(-1) 自動排成一列vecter,(-1,1)自動排成維度為1的一列
z.reshape(-1)
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
z.reshape(-1,1)
array([[ 1], [ 2], [ 3], [ 4], [ 5], [ 6], [ 7], [ 8], [ 9], [10], [11], [12], [13], [14], [15], [16]])
np.vstack(tup)使用
沿著豎直方向將矩陣堆疊起來。
Note: the arrays must have the same shape along all but the first axis.除開第一維外,被堆疊的矩陣各維度要一致。
示例代碼:
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
res = np.vstack((arr1, arr2))
np.hstack(tup)
沿著水平方向將數組堆疊起來。
Note:
tup : sequence of ndarrays
All arrays must have the same shape along all but the second axis.
示例代碼:
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
res = np.hstack((arr1, arr2))
[1 2 3 4 5 6]
arr1 = np.array([[1, 2], [3, 4], [5, 6]])
arr2 = np.array([[7, 8], [9, 0], [0, 1]])
res = np.hstack((arr1, arr2))
[[1 2 7 8] [3 4 9 0] [5 6 0 1]]
np.random.shuffle(data) 打亂用
np.random.normal(0,1,(256,10)) # normalize (mean ,std , shape)
np.random.randint(0,3,size=(256)) # 0~3(不包含3)之間的亂整數,size為
遍歷索引又要遍曆元素時
enumerate還可以接收第二個參數,用於指定索引起始值
list1 = ["这", "是", "一个", "测试"]
for index, item in enumerate(list1):
print index, item
>>>
0 这
1 是
2 一个
3 测试
補充
如果要統計文件的行數,可以這樣寫:
count = len(open(filepath, 'r').readlines())
這種方法簡單,但是可能比較慢,當文件比較大時甚至不能工作。
可以利用enumerate():
count = 0
for index, line in enumerate(open(filepath,'r')):
count += 1
Seaborn是在Matplot的基礎上實作更高階的視覺化API,可以讓畫圖變得更方便、容易。我自己覺得Matplot跟Seaborn的關係就像是Tensorflow跟Keras。