首页 > 其他 > 详细

tensorflow2.0——创建张量2

时间:2020-07-27 16:41:22      阅读:109      评论:0      收藏:0      [点我收藏+]

 

技术分享图片

 

 

 

 技术分享图片

 

 

技术分享图片

 

 

技术分享图片

 

技术分享图片

 

技术分享图片

 

 

技术分享图片

 

技术分享图片

 

 

技术分享图片

 

import tensorflow as tf

############################创建全0全1张量#########################
a = tf.ones(shape = (3,5))
print(a:,a)
b = tf.ones([6])
print(b:,b)
c = tf.zeros([2,3],dtype = tf.int32)
print(c:,c)
print()
############################创建元素值都相同的张量#########################
a = tf.fill([3,4],3.9)
print(全相同张量fill():,a)
print()
a = tf.constant(value = 4.8,shape = [3,2])
print(全相同张量constant():,a)
print()
############################创建元素满足正态分布的张量#########################
a = tf.random.normal(shape = [3,4],mean = 0,stddev = 1,dtype = tf.float32)
print(正态分布为:,a)
print()
############################创建元素满足截断正态分布的张量#########################
a = tf.random.truncated_normal(shape = [3,4],mean = 0,stddev = 1,dtype = tf.float32)
print(截断正态分布为:,a)
print()
############################创建元素满足均匀分布的张量#########################
a = tf.random.uniform(shape = [4,5],minval = 0,maxval = 5,dtype = tf.int32)
print(均匀分布为:,a)
print()
############################随机打乱shuffle函数#########################
a = tf.constant([[1,2],[3,4],[5,6],[7,8]])                      #   只沿着第一维打乱
a = tf.random.shuffle(a)
print("打乱后的a:",a)
############################创建序列tf.range()函数#########################
a = tf.range(start = 0,limit = 10,delta = 2,dtype = tf.int32)
print(创建的序列为:,a)
############################查看张量的属性 ndim,shaoe,dtype#########################
a = tf.constant([[1,2],[3,4],[5,6],[7,8]])
print(维度ndim:,a.ndim)
print(数据类型dtype:,a.dtype)
print(shape:,a.shape)
print(tf.shape(a):,tf.shape(a))
print(元素总数tf.size(a):,tf.size(a))
print(张量维度tf.rank(a):,tf.rank(a))
print()

 

tensorflow2.0——创建张量2

原文:https://www.cnblogs.com/cxhzy/p/13385166.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!