np.around、np.reshape、np.squeeze

np.around、np.reshape、np.squeeze

1、np.around

1、四舍五入

2、当是.5时,最后取得证书要是偶数

In [17]: np.around([0.4,0.5,0.12,0.6,0.3,1.2,1.8,1.3])
Out[17]: array([0., 0., 0., 1., 0., 1., 2., 1.])

In [21]: np.round([0.5,1.5,2.5,3.5,4.5,5.5,6.5])
Out[21]: array([0., 2., 2., 4., 4., 6., 6.])

2、np.reshape

体会-1的意义

1、Reshape  (num_px, num_px, 3)    --->   (num_px ∗num_px ∗ 3, 1).

一个简单的小技巧:   shape (a,b,c,d)     --->    shape (b∗c∗d, a)

X_flatten = X.reshape(X.shape[0], -1).T      # X.T is the transpose of X

2、reshape(1,-1) 返回行向量

In [47]: a.reshape(1,-1)
Out[47]: array([[1, 2, 3, 4, 5, 6, 7, 8]])

3、reshape(-1,1)返回列向量

In [48]: a.reshape(-1,1)
Out[48]:array([[1],[2],[3],[4],[5], [6],[7],[8]])

 

3、np.squeeze

去掉shape为1的维度

cost = np.squeeze(cost)     # makes sure cost is the dimension we expect. 
                                              # E.g., turns [[17]] into 17 

 

 

 

你可能感兴趣的:(NumPy,numpy)