将数据定义为常量
在整个课程中,我们将使用 tensorflow 2.6.0,并且只导入完成每个练习所需的子模块。多数情况下系统会替您完成,但本练习需要您亲自从 tensorflow 导入 constant。
导入 constant 之后,您将把 numpy 数组 credit_numpy 转换为 tensorflow 常量 credit_constant。该数组包含来自信用卡持卡人数据集的特征列,预览见下图。我们将在后续章节继续使用该数据集。
请注意,tensorflow 2 允许您将数据表示为 numpy 数组,或 tensorflow 的 constant 对象。使用 constant 可确保对该对象执行的任何操作都在 tensorflow 中完成。

本练习是课程的一部分
Python 中的 TensorFlow 入门
练习说明
- 从
tensorflow模块导入constant子模块。 - 将
credit_numpy数组转换为tensorflow中的constant对象。不要设置数据类型。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import constant from TensorFlow
from tensorflow import ____
# Convert the credit_numpy array into a tensorflow constant
credit_constant = constant(____)
# Print constant datatype
print('\n The datatype is:', credit_constant.dtype)
# Print constant shape
print('\n The shape is:', credit_constant.shape)