开始使用免费开始使用

设置数据类型

在本练习中,您将同时加载数据并设置其类型。注意,housing 已可用,且已将 pandaspd 导入。您将导入 numpytensorflow,并使用 housing 中的列定义可在 tensorflow 中使用的张量,并指定相应的数据类型。回忆一下,您可以通过 housing['price']housing 中选择 price 列。

本练习是课程的一部分

Python 中的 TensorFlow 入门

查看课程

练习说明

  • 以标准别名导入 numpytensorflow
  • 使用 numpy 数组将张量 price 设置为 32 位浮点数的数据类型。
  • 使用 tensorflow 函数 cast() 将张量 waterfront 设置为布尔数据类型。
  • 依次打印 pricewaterfront。您是否注意到任何重要差异?

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import numpy and tensorflow with their standard aliases
____
____

# Use a numpy array to define price as a 32-bit float
price = np.____(housing['price'], np.____)

# Define waterfront as a Boolean using cast
waterfront = tf.____(housing['waterfront'], tf.____)

# Print price and waterfront
print(____)
print(____)
编辑并运行代码