设置数据类型
在本练习中,您将同时加载数据并设置其类型。注意,housing 已可用,且已将 pandas 以 pd 导入。您将导入 numpy 和 tensorflow,并使用 housing 中的列定义可在 tensorflow 中使用的张量,并指定相应的数据类型。回忆一下,您可以通过 housing['price'] 从 housing 中选择 price 列。
本练习是课程的一部分
Python 中的 TensorFlow 入门
练习说明
- 以标准别名导入
numpy和tensorflow。 - 使用
numpy数组将张量price设置为 32 位浮点数的数据类型。 - 使用
tensorflow函数cast()将张量waterfront设置为布尔数据类型。 - 依次打印
price和waterfront。您是否注意到任何重要差异?
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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(____)