收藏   订阅   蔚来影讯
你现在的位置:首页 » 业余爱好 » 正文

tensor有哪些属性?rank device shape ones is_tensor isinstance dtype

时间:2019年08月13日 18:39:06 | 作者 :老马 | 分类 : 业余爱好 | 浏览:794 | 评论:0

如果对python或者tensor感兴趣,欢迎加微信wangqime 作为新手讨论交流也算是一种印象加深 提升的方式

#tensor属性 device:tensor程序所在的设备名称
with tf.device('cpu'):
    a = tf.constant(123)
    print(a.device)

# a如果在cpu上 转移到gpu上运行的话如下:
with tf.device('cpu'):
    a = tf.constant([[1, 2, 3], [2, 5, 6], [8, 9, 10]])
# a = a.gpu()
# print(a.device)

# tensor数据类型转换为numpy类型
print(a.numpy())
# 查看tensor数据类型的行列数,形状shape属性
print(a.shape)
# 查看tensor数据类型的纬度ndim属性 或者 tf.rank(tensor)方法
print(a.ndim)
print(tf.rank(a))
# 举例多维的打印纬度
mytf = tf.ones([4, 5, 3], dtype=tf.int32)
print(tf.rank(mytf))
print(mytf)

# 是否为tensor数据方法:tf.is_tensor(tensor) 或 isinstance(tensor,tf.Tensor)
print(tf.is_tensor(mytf))
print(isinstance(mytf, tf.Tensor))
print('---------')
# dtype 属性判断tensor数据类型
print(mytf.dtype)

tensor数据的方法 和 属性有:

# tensor 指某个tf数据,比如 [[1 1 1 1],[1 1 1 1]]
tf.device()
tensor.cpu()
tensor.gpu()

tensor.numpy()
tf.rank(tensor)
tf.ones()
tf.is_tensor()
isinstance()
-------------------
tensor.dtype
tensor.shape


上一篇:如何创建tensor数据 创建tensor数据的函数 下一篇:守护神之绝境营救成本是4000万还是1.6亿元?
本站致力于揭露全国影视投资诈骗案件 避免更多老百姓受骗上当
经历分享 请投稿

网络世界,不加微信QQ手机,留言沟通

发表评论

必填

回复后邮件通知

客服会联系您

◎欢迎参与讨论,聆听心声,下滑更多影视投资诈骗相关内容。

栏目
文章归档
标签列表