我想做这样的事情:
def f(ind, region, matrix):
...
参数ind是占位符或张量,并且包含中心元素的坐标x,y,区域是表示区域形状的整数元组。而且您需要计算索引并从矩阵中获取区域。
示例:
ind = [2, 2]
region = [3, 3]
matrix = [[1, 1, 1, 1, 1],
[2, 2, 2, 2, 2],
[3, 3, 3, 3, 3],
[4, 4, 4, 4, 4],
[5, 5, 5, 5, 5]]
indices = tf.placeholder(tf.in32, shape=...)
region = [3, 3]
mat = tf.placeholder(tf.float32, shape=...)
res = f(indices, region, mat)
with tf.Session() as sess:
r = sess.run(res, feed_dict={ indices: ind, mat: matrix })
结果是:
r = [[2, 2, 2],
[3, 3, 3],
[4, 4, 4]]
因为(2,2)上的中心元素为3,并且结果r给定大小为3×3的区域。