tensorflow的tf模块下的常用操作总结
1,tensorflow的数据类型:主要分为整形,浮点数,复数,字符串,bool
(1)tf.float16 半精度的16位浮点数
tf.float32 单精度的32位浮点数
tf.float64 双精度的64位浮点数
tf.bfloat 截断的16位浮点数
(2)tf.int8 tf.uint8 8位的有符号/无符号整形
tf.int16 tf.uint16
tf.int32
tf.int64
(3)tf.qint8 tf.quint8 量化的8为有符号/无符号整形
tf.qint16 tf.quint16
tf.qint32
(4)tf.complex64 64位复数
tf.complex128
(5)tf.string 字符串
(6)tf.bool
2,tensorflow下的算法操作
(1)tf.add(x,y,name=None)
(2)tf.subtract(x,y,name=None)
(3)tf.multiply(x,y,name=None)
(4)tf.scalar_mul(scalar,x) #标量相乘
(5)tf.div(x,y)
(6)tf.divide(x,y)
(7)tf.turediv(x,y) #5,6,7都是猪元素相除
(8)tf.floordiv(x,y) #floor方式对结果向下取整
(9)tf.truncatediv(x,y) #以截断的方式对结果进行取整
(10) tf.realdiv(x,y) #返回实数类型的 x / y
(11)tf.mod(x,y) #对应元素相除后取余数
(12)tf.floormod()
(13)tf.trunctedmod()
3,tensorflow下对tensor的基本操作
(1)tf.add_n(inputs) #input是一个同类型的tensor的列表,将列表中的所有tensor对应的元素相加
(2)tf.abs(x)
(3)tf.negative(x)
(4)tf.sign(x)
(5)tf.reciprocal(x) #倒数
(6)tf.square(x)
(7)tf.sqrt() tf.rsqrt() #开方后的倒数
(8)tf.floor()
tf.ceil()
tf.round()
(9)tf.pow(x,y)
(10)tf.exp(x) tf.expm1()
(11)tf.log() tf.log1p()
(12)tf.maximum(x,y)
tf.minimum(x,y)
(13)tf.sin() tf.arcsin()
tf.cos() tf.arccos()
tf.tan() tf.arctan()
(14)tf.erf()
4,矩阵操作
(1)tf.diag(diagnal,name=None)
(2)tf.diag_part(input)
(3)tf.trace()
(4)tf.tranpose()
(5)tf.eye()
(6)tf.matrix_diag(input)
(7)tf.matrix_diag_part(input)
(8)tf.matrix_band_part()
(9)tf.matrix_set_diag(diagnal)
(10)tf.matrix_tranpose(x)
(11)tf.matmul(x,y) tf.tensordot()
(12)tf.norm(tensor,ord=“euclidean”)
(13)tf.matrix_inverse(x)
(14)tf.qr()
(15)tf.svd()
5,复数的操作
(1)tf.complex(real,imag) #由两个实数转换为复数
(2)tf.conj(x) 返回共轭
(3)tf.real(x)
(4)tf.imag(x)
5,归约计算
(1)tf.reduce_sum(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(2)tf.reduce_mean(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(3)tf.reduce_max(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(4)tf.reduce_min(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(5)tf.reduce_prod(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(6)tf.reduce_all(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(7)tf.reduce_any(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(8)tf.reduce_logsumexp(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(9)tf.count_nonzero(input_tensor,axis=None,keep_dims=False,name=None,reduction_indices=NOne)
(10)tf.accumulate_n()
(11)tf.einsum()
6,张量扫描
(1)tf.cumsum(x,axis=0,exclusive=False,reverse=False,name=None) #连加
(2)tf.sumprod(x,axis=0,exclusive=False,reverse=False,name=None) #连乘
7,张量分段
(1)tf.segment_sum(data,segment_ids,name=None)
(2)tf.segment_prod(data,segment_ids,name=None)
(3)tf.segment_mean(data,segment_ids,name=None)
(4)tf.segment_max(data,segment_ids,name=None)
(5)tf.segment_min(data,segment_ids,name=None)
(6)tf.unsorted_segment_sum(data,segment_ids,name=None)
(7)tf.sparse_segment_sum(data,indices,segment_ids,name=Noe,num_segments=None)
(8)tf.sparse_segment_mean(data,indices,segment_ids,name=Noe,num_segments=None)
(9)tf.sparse_segment_sqrt(data,indices,segment_ids,name=Noe,num_segments=None)
8,序列比较与序列提取
(1)tf.argmax(input,axis,name=None)
(2)tf.argmin(input,axis,name=None)
(3)tf.where(condition,x,y)
(4)tf.unique(x,out_idx=tf.int32)
(5)tf.invert_permutation(x) #将数据和索引置换
9,切片与合并
(1)tf.slice(input,begin,size,name=None)
(2)tf.split(value,num_or_size_split,axis=0,num=None)
(3)tf.concat(values,axis)
(4)tf.parallel_stack(values)
(5)tf.reverse(x,axis=[0])
(6)tf.ont_hot(indices,depth,on_value=1,off_value=0,axis=None,dtype=None)
10,形状操作
(1)tf.shape(x)
(2)tf.size(x)
(3)tf.rank(x)
(4)tf.reshape(x,shape)
(5)tf.expand_dims(inout,axis=None)
11,数据类型转换
(1)tf.string_to_number(string_tensor)
(2)tf.to_int32()
(3)tf.to_int64()
(4)tf.to_float()
(5)tf.to_double()
(6)tf.cast(x,dtype)