Tensor merger and segmentation

First look at what used to merge and split the interface tensor:

tf.concat tensor used for splicing, tf.stack used for stacking tensor, tensor tf.split used for segmentation, tf.unstack a tf.split also used for tensor segmentation

1.tf.concat

Axis represents the parameter that will be merged dimensions

# Assume that a score representative of four classes (class 35, 8 subjects), b represent 2 classes score 
a tf.ones = ([4,35,8 ])
B = tf.ones ([2,35,8 ])
 # use concat merged results obtained six classes 
C = tf.concat ([A, B], Axis = 0)
 # (6,35,8) 
Print (c.shape)

2.tf.stack (for creating a new dimension)

# Assume that a score of four classes (class 35, 8 subjects) represents A school, b B represents school accomplishments four classes 
a tf.ones = ([4,35,8 ])
B = tf.ones ([4,35,8 ])
 # using stack merged results obtained six classes 
C = tf.stack ([A, B], Axis = 0)
 # (2,4,35,8 ) 
Print (c.shape)

3.tf.unstack (aliquoted to a dimension)

# Assume that a score of four classes (class 35, 8 subjects) represents A school, b B represents school accomplishments four classes 
a tf.ones = ([4,35,8 ])
B = tf.ones ([4,35,8 ])
 # using stack merged results obtained six classes 
C = tf.stack ([A, B], Axis = 0)
 # (2,4,35,8 ) 
Print (c.shape)
aa,bb=tf.unstack(c,axis=0)
# (4,35,8)
print(aa.shape,bb.shape)
res=tf.unstack(c,axis=3)
# (2,4,35)
print(res[0].shape,res[7].shape)

4.tf.split (scale break)

# Assume that a score of four classes (class 35, 8 subjects) represents A school, b B represents school accomplishments four classes 
a tf.ones = ([4,35,8 ])
B = tf.ones ([4,35,8 ])
 # using stack merged results obtained six classes 
C = tf.stack ([A, B], Axis = 0)
 # (2,4,35,8 ) 
Print (c.shape)
res = tf.split(c,axis=3,num_or_size_splits=2)
# 2,(2,4,35,4)
print(len(res),res[0].shape,res[1].shape)
res = tf.split(c,axis=3,num_or_size_splits=[2,2,4])
# 3 (2,4,35,2) (2,4,35,2) (2,4,35,4)
print(len(res),res[0].shape,res[1].shape,res[2].shape)

Guess you like

Origin www.cnblogs.com/zdm-code/p/12229527.html