#!/usr/bin/env python
# encoding: utf-8
'''
@author: lele Ye
@contact: 1750112338@qq.com
@software: pycharm 2018.2
@file: 4-3注入机制.py
@time: 2018/10/12 21:45
@desc:
'''
import tensorflow as tf
import numpy as np
# 定义一个数据类型为tf.int32的占位符
a = tf.placeholder(tf.int32)
b = tf.placeholder(tf.int32)
# 将占位符的两个值相加
add = tf.add(a, b)
# 将占位符的两个值相乘
mul = tf.multiply(a, b)
#定义两个矩阵,并将其转为tensor
mask_a = tf.convert_to_tensor(2 * np.ones((3, 3), dtype=np.uint8))
mask_b = tf.convert_to_tensor(3 * np.ones((3, 3), dtype='uint8'))
# 将两个tensor进行相加
mask_re = tf.add(mask_a, mask_b)
with tf.Session() as sess:
    print(sess.run(mask_re))
    print("相加 %i" % sess.run(add, feed_dict={a: 3, b: 4}))
    print("相乘 %i" % sess.run(mul, feed_dict={a: 3, b: 4}))
    print("相加&相乘", sess.run([add, mul], feed_dict={a: 3, b: 4}))

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐