热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

python–tensorlow.constant()

python–tensorlow.constant()哎哎哎

python–tensorlow . constant()

哎哎哎:# t0]https://www . geeksforgeeks . org/python-tensorlow-constant/

TensorFlow 是谷歌设计的开源 Python 库,用于开发机器学习模型和深度学习神经网络。

常量()用于从像列表一样的张量对象创建张量。

语法: tensorflow.constant(值、数据类型、形状、名称)

参数:


  • 值:是需要转换为 Tensor 的值。

  • 数据类型(可选):定义输出张量的类型。

  • 形状(可选):定义输出张量的维度。

  • 名称(选项 a): 定义操作的名称。

返回:返回张量。

示例 1: 来自 Python 列表

Python 3


# Importing the library
import tensorflow as tf
# Initializing the input
l = [1, 2, 3, 4]
# Printing the input
print('l: ', l)
# Calculating result
x = tf.constant(l)
# Printing the result
print('x: ', x)

输出:

l: [1, 2, 3, 4]
x: tf.Tensor([1 2 3 4], shape=(4, ), dtype=int32)

示例 2: 来自 Python 元组

Python 3


# Importing the library
import tensorflow as tf
# Initializing the input
l = (1, 2, 3, 4)
# Printing the input
print('l: ', l)
# Calculating result
x = tf.constant(l, dtype = tf.float64)
# Printing the result
print('x: ', x)

输出:

l: (1, 2, 3, 4)
x: tf.Tensor([1\. 2\. 3\. 4.], shape=(4, ), dtype=float64)


推荐阅读
author-avatar
世界和平啊
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有