始める無料で始める

データを定数として定義する

このコース全体で tensorflow バージョン 2.6.0 を使用し、各演習に必要なサブモジュールだけをインポートします。通常はすでに用意されていますが、この演習ではあなた自身で tensorflow から constant をインポートします。

constant をインポートしたら、numpy 配列である credit_numpytensorflow の定数 credit_constant に変換します。この配列には、クレジットカード保有者のデータセットから抽出した特徴量の列が含まれており、下の画像でプレビューしています。このデータセットには後の章で再び取り組みます。

tensorflow 2 では、データを numpy 配列としても、tensorflowconstant オブジェクトとしても扱えます。constant を使うと、そのオブジェクトに対して行う演算はすべて tensorflow 上で実行されます。

This image shows four feature columns from a dataset on credit card default: education, marriage, age, and bill amount.

この演習はコースの一部です

Introduction to TensorFlow in Python

コースを見る

演習の手順

  • tensorflow モジュールからサブモジュール constant をインポートします。
  • credit_numpy 配列を tensorflowconstant オブジェクトに変換します。データ型は設定しないでください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# 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)
コードを編集して実行