x.reshape python 函数用法简介

print '改成2行3列:'print c.reshape(2,3)
print '改成3行2列:'print c.reshape(3,2)
print '我也不知道几行,反正是1列:'print c.reshape(-1,1)
print '我也不知道几列,反正是1行:'print c.reshape(1,-1)
print '不分行列,改成1串'print c.reshape(-1)

题主是在用tensorflow做卷积神经网络入门的手写数字识别吧,
源码:x_image = tf.reshape(x, [-1, 28, 28, 1])
这里是将一组图像矩阵x重建为新的矩阵,该新矩阵的维数为(a,28,28,1),其中-1表示a由实际情况来定。例如,x是一组图像的矩阵(假设是50张,大小为56×56),则执行
x_image = tf.reshape(x, [-1, 28, 28, 1])
可以计算a=50×56×56/28/28/1=200。即x_image的维数为(200,28,28,1)。


猜你喜欢

转载自blog.csdn.net/liangjiubujiu/article/details/80976372
今日推荐