导入tensorflow
import tensorflow as tf
输出tensorflow的版本
print(tf.__version__)
创建tensor
x = tf.constant(range(12))
tensor的形状x.shape
tensor的长度len(x)
改变tensor的形状
X=tf.reshape(x,(3,4))
X=tf.reshape(x,(-1,4))
X=tf.reshape(x,(3,-1))
同过Python的列表list创建tensor
tf.constant([[2,2,3,4]])
全0tensor
tf.zeros((2,3,4))
全1tensor
tf.ones((3,4))
正太随机tensor
tf.random.normal(shape=[3,4],mean=0,stddev=1)