np.squeeze()

作用:从数组的形状中删除单维条目,即把shape中为1的维度去掉

例子:

import numpy as np

a = np.array([[1], [2], [3]])
print(a)
print(a.shape)

输出:

[[1]
 [2]
 [3]]
shape:(3, 1)

应用squeeze()后:

a1 = np.squeeze(a)
print(a1)
print(a1.shape)

[1 2 3]
shape:(3,)

应用:

在预测分析中用于处理预测数组和真实值数组以方便计算预测值与真实值之间的误差:

predictions = np.array(predictions).squeeze() 
labels = np.array(labels).squeeze() 
rmse = np.sqrt(((predictions - labels) ** 2).mean(axis=O)) 

 

你可能感兴趣的:(TensorFlow)