假设我要通过沿一个特定轴交织来合并两个3D张量流张量a和b。例如,张量a具有形状(3,3,2),张量b具有形状(3,2,2)。我想创建一个沿轴1交错的张量c,从而得到形状为(3,5,2)的张量。
示例:
a = [[[1,1],[2,2],[3,3]],
[[4,4],[5,5],[6,6]],
[[7,7],[8,8],[9,9]]]
b = [[[10,10],[11,11]],
[[12,12],[13,13]],
[[14,14],[15,15]]]
c = [[[1,1],[10,10],[2,2],[11,11],[3,3]],
[[4,4],[12,12],[5,5],[13,13],[6,6]],
[[7,7],[14,14],[8,8],[15,15],[9,9]]]
答案 0 :(得分:1)
您可以先重新排列列的索引。
componentWillReceiveProps(props){
if (props.validatePass) {
this.props.updateStrongPassword(param1, param2, param3,
param4);
}
}
render()
{
... // screen render method
..
<Button onPress={() => { this.submit(); }}>Change Password</Button>
}
//Here is the submit function:
submit() {
//first service call
this.props.validatePassword(param1, param2, param3, param4);
}
然后,您应该为import tensorflow as tf
a = [[[1,1],[2,2],[3,3]],
[[4,4],[5,5],[6,6]],
[[7,7],[8,8],[9,9]]]
b = [[[10,10],[11,11]],
[[12,12],[13,13]],
[[14,14],[15,15]]]
a_tf = tf.constant(a)
b_tf = tf.constant(b)
a_tf_column = tf.range(a_tf.shape[1])*2
# [0 2 4]
b_tf_column = tf.range(b_tf.shape[1])*2+1
# [1 3]
column_indices = tf.concat([a_tf_column,b_tf_column],axis=-1)
# Before TF v1.13
column_indices = tf.contrib.framework.argsort(column_indices)
## From TF v1.13
# column_indices = tf.argsort(column_indices)
# [0 3 1 4 2]
创建新索引。
tf.gather_nd()
最后,您应合并column,row = tf.meshgrid(column_indices,tf.range(a_tf.shape[0]))
combine_indices = tf.stack([row,column],axis=-1)
# [[[0,0],[0,3],[0,1],[0,4],[0,2]],
# [[1,0],[1,3],[1,1],[1,4],[1,2]],
# [[2,0],[2,3],[2,1],[2,4],[2,2]]]
和a
的值,并使用b
获得结果。
tf.gather_nd()