我想把一个数组复制到另一个大小不同的数组。 我想要这样的函数:
blit(destimg,src,dstlocation)
例如blit(zeros((7,7)),ones((3,3)),(4,4))
会导致
^{pr2}$数组src
的左上中心现在位于数组destimg
的位置(4,4)
。在
如果我做了blit(zeros((7,7)),ones((3,3)),(5,5))
我会得到:
array([[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 1., 1.],
[ 0., 0., 0., 0., 0., 1., 1.]])
数组src
不适合destimg
,但它的左上角仍然位于右侧位置。在
您只需计算适当的切片:
收益率
^{pr2}$以及
收益率
我能够找到一个解决方案(有点冗长),一定有一个更优雅的方式,但在中间时间这将做。在
产量:
^{pr2}$以及
收益率
以下是我的实现:
相关问题 更多 >
编程相关推荐