1 tf.shape()
import tensorflow as tf
import numpy as np
a_array = np.array([[1,2,3], [4,5,6]])
b_list = [[1,2,3],[3,4,5]]
c_tensor = tf.constant([[1,2,3], [4,5,6]])
with tf.Session() as sess:
print(sess.run(tf.shape(a_array)))
print(sess.run(tf.shape(b_list)))
print(sess.run(tf.shape(c_tensor)))
>>> [2,3], [2,3], [2,3]
2 x.get_shape().as_list()
x.get_shape(), 只有tensor才可以使用这种方法,返回的是一个元组
import tensorflow as tf
import numpy as np
a_array = np.array([[1,2,3], [4,5,6]])
b_list = [[1,2,3],[3,4,5]]
c_tensor = tf.constant([[1,2,3], [4,5,6]])
print(c_tensor.get_shape())
print(c_tensor.get_shape().as_list())
with tf.Session() as sess:
print(sess.run(tf.shape(a_array)))
print(sess.run(tf.shape(b_list)))
print(sess.run(tf.shape(c_tensor)))
>>> (2,3), [2,3], [2,3], [2,3], [2,3]
3 tf.split()
tf.split(dimension, num_split, input):dimension的意思就是输入张量的哪一个维度,如果是0就表示对第0维度进行切割。num_split就是切割的数量,如果是2就表示输入张量被切成2份,每一份是一个列表。
import tensorflow as tf
import numpy as np
A = [[1,2,3], [4,5,6]]
x = tf.split(1,3,A)
with tf.Session() as sess:
c = sess.run(x)
for ele in c:
print(ele)
>>>[[1],
[4]]
[[2],
[5]]
[[3],
[6]]