import tensorflow as tf
tf.compat.v1.disable_eager_execution()#根据网上查到的代码粘贴进去的
tf.zeros([3,4]) #定义3行4列元素均为0的矩阵
tensor=tf.constant([1,2,3,4])#定义一维向量常量
#'tensor' =[[1,2,3],[4,5,6]]
tf.ones_like(tensor) #定义大小和tensor变量大小相同的元素均为1的矩阵
tensor1=tf.constant(1.0,shape=[2,3])#定义2行3列元素均为1.0的常量矩阵
tf.linspace(1.0, 6.0, 1, name="linspac")#起始值为1.0,终止值为6.0,步长为1
tf.range=(1,0, 6.0, 1)#start=1.0,limit=6.0,delta=1(不包括6.0)
norm = tf.random.normal([3,4],mean =1, stddev =4)#3行4列均值为1,标准差为4的随机矩阵
shuff = tf.random.shuffle(tensor),#随机打乱矩阵中元素的位置
with tf.compat.v1.Session() as sess:
print(sess.run(norm))
print(sess.run(shuff))
运行结果形式如下,每次运行结果都会改变
[[ 1.7575849 -1.6020312 -9.258903 5.798862 ]
[ 0.76005447 4.9886518 -3.7372637 5.7758336 ]
[-2.1033041 -6.386596 4.228735 3.4100542 ]]
(array([4, 1, 3, 2], dtype=int32),)