import numpy as np
import matplotlib.pyplot as plt
def put(T,b,offset=(0,0)):
ny,nx = b.shape
i,j = offset
T[i:i+ny,j:j+nx] = b
nx,ny = 10, 20
T = np.zeros( (ny,nx),dtype=np.int)
b = np.array([ [1,0],[1,0],[1,0],[1,1] ],dtype=np.int)
put(T,b,(0,2))
put(T,b,(ny-1-3,1))
put(T,b.T,(ny-1-3,5))
put(T,b.T[::-1,:],(ny-1-2,3))
plt.imshow(T)
<matplotlib.image.AxesImage at 0x122e904e0>
np.sum(np.cumsum(T[10::-1,:],axis=0)>0,axis=0)
array([0, 0, 4, 4, 0, 0, 0, 0, 0, 0])
np.max(np.sum(np.cumsum(T[10:,:],axis=0)>0,axis=0)+\
np.sum(np.cumsum(T[10::-1,:],axis=0)>0,axis=0))
6
plt.imshow(np.cumsum(T[10::-1,:],axis=0)>0,extent=[0,nx,0,10])
<matplotlib.image.AxesImage at 0x1236e4710>
plt.imshow(np.cumsum(T[10:,:],axis=0)>0,extent=[0,nx,0,10])
<matplotlib.image.AxesImage at 0x1239213c8>
plt.imshow(np.cumsum(b[::,:],axis=0)>0)
<matplotlib.image.AxesImage at 0x122980320>