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]])

扫描二维码关注公众号,回复: 6388126 查看本文章

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))

 [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。

https://medium.com/jameslearningnote/%E8%B3%87%E6%96%99%E5%88%86%E6%9E%90-%E6%A9%9F%E5%99%A8%E5%AD%B8%E7%BF%92-%E7%AC%AC2-5%E8%AC%9B-%E8%B3%87%E6%96%99%E8%A6%96%E8%A6%BA%E5%8C%96-matplotlib-seaborn-plotly-75cd353d6d3f

猜你喜欢

转载自www.cnblogs.com/pyleu1028/p/10995691.html
np