我想通过4个子传感器得到更大的张量和交错索引。你知道吗
我的问题是:
四个输入,带形状[批次x 2m x 2n x 1]
输出形状为[batch x 4m x 4n x 1]
索引\u y \u 0 \u 1=[0,1,4,5,8,9…], 索引\u y\u 2 \u 3=[2,3,6,7,10,11…]
索引\u x \u 0 \u 1=[0,1,4,5,8,9…], 索引\u x \u 2 \u 3=[2,3,6,7,10,11…]
输出[索引\u y\u 0\u 1,索引\u x\u 0\u 1]=输入0
输出[索引\u y \u 0 \u 1,索引\u x \u 2 \u 3]=输入1
输出[索引\u y \u 2 \u 3,索引\u x \u 0 \u 1]=输入2
输出[索引\ y \ U 2 \ U 3,索引\ x \ U 2 \ U 3]=输入3
下面是我关于python代码的问题:
import numpy as np
UpperLeft = np.ones((3,2,4,1))
UpperRight = np.ones((3,2,4,1))*2
BottonLeft = np.ones((3,2,4,1))*3
BottonRight = np.ones((3,2,4,1))*4
output = np.zeros((UpperLeft.shape[0], UpperLeft.shape[1]*2, UpperLeft.shape[2]*2, 1))
assert(output.shape[1]%4 == 0)
assert(output.shape[2]%4 == 0)
# UpperLeft Assignment
start_y = 0
start_x = 0
output[:,(start_y + 0)::4, (start_x + 0)::4, :] = UpperLeft[:,0::2, 0::2, :]
output[:,(start_y + 0)::4, (start_x + 1)::4, :] = UpperLeft[:,0::2, 1::2, :]
output[:,(start_y + 1)::4, (start_x + 0)::4, :] = UpperLeft[:,1::2, 0::2, :]
output[:,(start_y + 1)::4, (start_x + 1)::4, :] = UpperLeft[:,1::2, 1::2, :]
# UpperRight Assignment
start_y = 0
start_x = 2
output[:,(start_y + 0)::4, (start_x + 0)::4, :] = UpperRight[:,0::2, 0::2, :]
output[:,(start_y + 0)::4, (start_x + 1)::4, :] = UpperRight[:,0::2, 1::2, :]
output[:,(start_y + 1)::4, (start_x + 0)::4, :] = UpperRight[:,1::2, 0::2, :]
output[:,(start_y + 1)::4, (start_x + 1)::4, :] = UpperRight[:,1::2, 1::2, :]
# BottonLeft Assignment
start_y = 2
start_x = 0
output[:,(start_y + 0)::4, (start_x + 0)::4, :] = BottonLeft[:,0::2, 0::2, :]
output[:,(start_y + 0)::4, (start_x + 1)::4, :] = BottonLeft[:,0::2, 1::2, :]
output[:,(start_y + 1)::4, (start_x + 0)::4, :] = BottonLeft[:,1::2, 0::2, :]
output[:,(start_y + 1)::4, (start_x + 1)::4, :] = BottonLeft[:,1::2, 1::2, :]
# BottonRight Assignment
start_y = 2
start_x = 2
output[:,(start_y + 0)::4, (start_x + 0)::4, :] = BottonRight[:,0::2, 0::2, :]
output[:,(start_y + 0)::4, (start_x + 1)::4, :] = BottonRight[:,0::2, 1::2, :]
output[:,(start_y + 1)::4, (start_x + 0)::4, :] = BottonRight[:,1::2, 0::2, :]
output[:,(start_y + 1)::4, (start_x + 1)::4, :] = BottonRight[:,1::2, 1::2, :]
show_out = output[0,:,:,0]
如何在tensorflow上执行此操作?谢谢!你知道吗
你可以有一个函数,像这样在一个轴上交错张量。你知道吗
然后您可以使用它来交错第一个维度和另一个维度。你知道吗
相关问题 更多 >
编程相关推荐