python学习日记7tensorflow-矩阵运算

写了测试小程序

import tensorflow as tf
sess =tf.Session()
a=tf.ones([2,3],tf.int32)
print(sess.run(a))
b=tf.zeros([2,3],tf.int32)
print(sess.run(b))
c=tf.reshape([1,2,3,4,5,6],[3,2])
print(sess.run©)
d=tf.matmul(c,a)
print(sess.run(d))
e=tf.matmul(a,c)
print(‘matmul:’,sess.run(e))
f=tf.reshape([1,2,3,4],[4,-1])
print(‘reshape:’,sess.run(f))
g=tf.add(a,tf.transpose©)
print(‘add:’,sess.run(g))
h=tf.multiply(a,tf.transpose©)
print(‘multiply:’,sess.run(h))

运行结果

[[1 1 1]
[1 1 1]]
[[0 0 0]
[0 0 0]]
[[1 2]
[3 4]
[5 6]]
[[ 3 3 3]
[ 7 7 7]
[11 11 11]]
matmul: [[ 9 12]
[ 9 12]]
reshape: [[1]
[2]
[3]
[4]]
add: [[2 4 6]
[3 5 7]]
multiply: [[1 3 5]
[2 4 6]]

你可能感兴趣的:(python,tensorflow)