本文共 1035 字,大约阅读时间需要 3 分钟。
import osos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' #CPU的分配问题import numpy"""Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly."""import tensorflow as tfmatrix1 = tf.constant([[3, 3]])matrix2 = tf.constant([[2], [2]])product = tf.matmul(matrix1, matrix2) # matrix multiply np.dot(m1, m2)# method 1sess = tf.compat.v1.Session()result = sess.run(product)print(result)sess.close()# method 2with tf.compat.v1.Session() as sess: result2 = sess.run(product) print(result2)
#初始化cup的分配import osos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'"""Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly."""import tensorflow as tfinput1 = tf.compat.v1.placeholder(tf.float32)input2 = tf.compat.v1.placeholder(tf.float32)ouput = tf.multiply(input1, input2)with tf.compat.v1.Session() as sess: print(sess.run(ouput, feed_dict={ input1: [7.], input2: [2.]}))
matmul和multiply区别参考文章:
转载地址:http://tfkrn.baihongyu.com/