shape的简单使用
使用.shape得到张量的维数,.shape[x]表示第x维上数量。
import tensorflow as tf
import numpy as np
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
a = np.array([[1, 2, 3],
[4, 5, 6]])
b = tf.convert_to_tensor(a)
print('b.shape=', b.shape)
print('b.shape[0]=', b.shape[0])
print('b.shape[1]=', b.shape[1])
结果:
b.shape= (2, 3)
b.shape[0]= 2
b.shape[1]= 3
Process finished with exit code 0
991

被折叠的 条评论
为什么被折叠?



