LoginSignup
2
3

More than 5 years have passed since last update.

TensorFlowの基本演算の表示

Last updated at Posted at 2017-10-17

TensorFlowの基本演算の表示

TensorFlowの基本演算は単純にprint(tf.div(2, 3))のようには表示できません。TensorFlowで基本演算などを表示させるには次のようにします。

print.py
import tensrflow as tf
sess = tf.Session()

print(sess.run(tf.div(2, 3)))
# div():戻り値は入力の型と同じ型になります。

print(sess.run(tf.truediv(2, 3)))
# truediv():python3の除算と同じです。

print(sess.run(tf.floordiv(2.0, 3.0)))
# floordiv():これは演算結果を最も近い整数に丸めこみます。

上記にTensorFlowでの演算を示しました。
まずはimport tensorflow as tfでtensorflowライブラリを読み込みます。
sess = tf.Session()によりセッションを開始します。
セッションはtensorflowを使用するためのおまじないのようなものだと最初のうちは思っておいてください。

print(sees.run(表示したい演算処理))により表示することができます。

以上がTensorFlowで演算を表示する方法です。
以下にTensorFlowの基礎をまとめている参照先を貼っておきます。

参考

https://qiita.com/rindai87/items/4b6f985c0583772a2e21 (TensorFlowの基礎)

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3