tensorflow基础教程 安装教程pycharm创建基础demo 安装教程 conda install tensorflow pycharm创建基础demo # 引入 tensorflow 模块 import tensorflow as tf # 创建一个整型常量,即 0 阶 Tensor t0 = tf.constant(3, dtype=tf.int32) # 创建一个浮点数的一维数组,即 1 阶 Tensor t1 = tf.constant([3., 4.1, 5.2], dtype=tf.float32) # 创建一个字符串的2x2数组,即 2 阶 Tensor t2 = tf.constant([['Apple', 'Orange'], ['Potato', 'Tomato']], dtype=tf.string) # 创建一个 2x3x1 数组,即 3 阶张量,数据类型默认为整型 t3 = tf.constant([[[5], [6], [7]], [[4], [3], [2]]]) # 打印上面创建的几个 Tensor print(t0) print(t1) print(t2) sess = tf.Session() print(sess.run(t3)) #构建计算图 import tensorflow as tf node1 = tf.constant(32.3) node2 = tf.constant(4.3) adder = node1 + node2 print(adder) sess = tf.Session() print(sess.run(adder)) #创建占位Tensor节点 import tensorflow as tf a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) adder = a + b print(a) print(b) print(adder) sess = tf.Session() print(sess.run(adder,{a:3,b:4.5})) print(sess.run(adder,{a:[1,3],b:[2,4]})) 源码地址