設定資料型別
在這個練習中,你會同時載入資料並設定其型別。請注意,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(____)