開始使用免費開始

設定資料型別

在這個練習中,你會同時載入資料並設定其型別。請注意,housing 已可使用,且已將 pandaspd 匯入。你將匯入 numpytensorflow,並使用 housing 中的欄位,依指定的資料型別定義可在 tensorflow 中使用的張量。回想一下,你可以像這樣從 housing 選取 price 欄位:housing['price']

本練習屬於課程

Python 的 TensorFlow 入門

檢視課程

練習說明

  • 以標準別名匯入 numpytensorflow
  • 使用 numpy 陣列,將張量 price 設為 32 位元浮點數的資料型別。
  • 使用 tensorflowcast() 函式,將張量 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(____)
編輯並執行程式碼