Matrix Operations

一 Code example

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf 
import numpy as np 
A = tf.constant([[1,2,3],[4,5,6]])
B = tf.fill([3,4],3)
C = tf.constant([[1,2,3,4],[11,22,33,44]])

with tf.Session() as sess:
    A_value = sess.run(A)
    B_value = sess.run(B)
    print('A_value
',A_value)
    print('B_value
',B_value)
    print('C_value
',sess.run(C))
    print('Matrix multiplication')
    matmal = tf.matmul(A,B)
    print(matmal)
    print('matmal_value
',sess.run(matmal))
    print('Matrix addition')
    add = tf.add(matmal,C)
    print(add)
    print('add_value
',sess.run(add))

二 Operation result

正是江南好风景
原文地址:https://www.cnblogs.com/monsterhy123/p/13069767.html