將資料定義為常數
在整個課程中,我們會使用 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)