tf.base(constant & Variable)
tf2除了tf.keras这个高级api的引入之外,其他的一些基础函数也发生了一些变化,就连最为基本的constant也发生了一些变化,比如在1.x里面constant建立的数组是不支持列数不一样的数组组合的,但是在2.0的版本里面,引入了RaggedTensor这个数据类型,也就实现了不规则数据的组合 import tensorflow as tf from tensorflow import keras t = tf . ragged . constant ( [ [ 1 . , 2 . , 3 . ] , [ 4 . , 5 . ] ] ) print ( t ) 可以看到这里的数据类型是RaggedTensor,我们也可以通过t.to_tensor()这个函数来完成数据类型从RaggedTensor转变为Tensor型,RaggedTensor类型除了可以进行简单的加减乘除以外,还可以通过tf.concat()函数来进行数组之间的拼接 t1 = tf . ragged . constant ( [ [ 5 . , 6 . ] , [ 7 . , 8 . ] ] ) print ( tf . concat ( ( t , t1 ) , axis = 0 ) ) 因为RaggedTensor类型在转变成tensor类型的时候,位数不够的自动补0