问题驱动
在使用python语言基于tensorflow框架搭建网络模型的时候,对于数据内容和shape的确定难免会参杂着使用numpy和tensorflow的内置函数,但是我们都知道ndarray为numpy的主要存储数据的格式,而tensor又是tensorflow的特色,下面来总结一下两者的转换方法
知识小结
- 对于直接调用tf.*形式的,返回值一般均为Tensor,无论是tf.constant, 还是占位符
import tensorflow as tf
a = tf.constant([1,2])
print(a) # out:Tensor("Const:0", shape=(2,), dtype=int32)
b = tf.placeholder(shape=[2, 2], dtype=tf.int32)