**
Tensorflow 机器学习项目实战 记录
**
基本操作
简单矩阵运算
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.constant([[2, 5, 3, -5],
[0, 3, -2, 5],
[4, 3, 5, 3],
[6, 1, 4, 0]])
y = tf.constant([[4, -7, 4, -3, 4],
[6, 4, -7, 4, 7],
[2, 3, 2, 1, 4],
[1, 5, 5, 5, 2]])
floatx = tf.constant([[2., 5., 3., -5.],
[0., 3., -2., 5.],
[4., 3., 5., 3.],
[6., 1., 4., 0.]])
# 矩阵转置
tf.transpose(x).eval()
array([[ 2, 0, 4, 6],
[ 5, 3, 3, 1],
[ 3, -2, 5, 4],
[-5, 5, 3, 0]])
#矩阵相乘 Matrix Multiplication
tf.matmul(x, y).eval()
array([[ 2, 0, 4, 6],
[ 5, 3, 3, 1],
[ 3, -2, 5, 4],
[-5, 5, 3, 0]])
#矩阵行列式(determinant)
tf.matrix_determinant(floatx).eval()
817.99969
#逆矩阵(inverse matrix)
tf.matrix_inverse(floatx).eval()
array([[-0.00855745, 0.10513447, -0.18948655, 0.29584354],
[ 0.12958434, 0.12224938, 0.01222495, -0.05134475],
[-0.01955992, -0.18826404, 0.28117359, -0.18092909],
[-0.08557458, 0.05134474, 0.10513448, -0.0415648 ]], dtype=float32)
#行列式求解
tf.matrix_solve(floatx, [[1],[1],[1],[1]]).eval()
array([[ 0.202934 ],
[ 0.21271393],
[-0.10757945],
[ 0.02933985]], dtype=float32)
**
约简(reduction)
**
x = tf.constant([[1, 2, 3],
[3, 2, 1],
[-1, -2, -3]])
boolean_tensor = tf.constant([[True, False, True],
[False, False, True],
[True, False, False]])
# 乘积方式降维,reduction_indices=1在