การกำหนดข้อมูลเป็น Constant
ตลอดคอร์สนี้ เราจะใช้ tensorflow เวอร์ชัน 2.6.0 และนำเข้าเฉพาะโมดูลย่อยที่จำเป็นสำหรับแต่ละแบบฝึกหัด โดยปกติจะเตรียมไว้ให้แล้ว แต่ในแบบฝึกหัดนี้ให้ทำเองโดยนำเข้า constant จาก tensorflow
เมื่อนำเข้า constant แล้ว ให้ใช้มันแปลงอาร์เรย์ numpy ชื่อ credit_numpy ให้เป็น tensorflow constant ชื่อ credit_constant อาร์เรย์นี้ประกอบด้วยคอลัมน์ฟีเจอร์จากชุดข้อมูลเกี่ยวกับผู้ถือบัตรเครดิต ดังที่แสดงในรูปด้านล่าง และเราจะกลับมาใช้ชุดข้อมูลนี้อีกครั้งในบทถัดไป
ขอให้สังเกตว่า tensorflow 2 รองรับการใช้ข้อมูลทั้งในรูปแบบ numpy array และ tensorflow constant object การใช้ constant จะช่วยให้มั่นใจได้ว่าการดำเนินการทั้งหมดที่เกิดขึ้นกับออบเจกต์นั้นจะถูกประมวลผลใน tensorflow

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
TensorFlow เบื้องต้นใน Python
คำแนะนำการฝึกหัด
- นำเข้าโมดูลย่อย
constantจากโมดูลtensorflow - แปลงอาร์เรย์
credit_numpyให้เป็นconstantobject ในtensorflowโดยไม่ต้องกำหนดชนิดข้อมูล
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# 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)