TensorFlow 返回tensor的 維數
阿新 • • 發佈:2019-02-04
如果tensor是用呼叫tensorflow框架定義的,那麼用 tensor_name.shape 即可返回tensorflow 的維數:
>>> import tensorflow as tf
>>> a=tf.constant([
... [[1.0,2.0,3.0,4.0],
... [5.0,6.0,7.0,8.0],
... [8.0,7.0,6.0,5.0],
... [4.0,3.0,2.0,1.0]],
... [[4.0,3.0,2.0,1.0],
... [8.0 ,7.0,6.0,5.0],
... [1.0,2.0,3.0,4.0],
... [5.0,6.0,7.0,8.0]]
... ])
>>> a.shape
TensorShape([Dimension(2), Dimension(4), Dimension(4)])
也可通過呼叫 numpy 來返回 tensor 的維數:
>>> import numpy as np
>>> np.shape(a)
TensorShape([Dimension(2), Dimension(4), Dimension(4 )])