#!/usr/bin/env python # coding: utf-8 # In[93]: import numpy as np import matplotlib.pyplot as plt # In[102]: def put(T,b,offset=(0,0)): ny,nx = b.shape i,j = offset T[i:i+ny,j:j+nx] = b # In[103]: 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) # In[104]: 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)) # In[130]: plt.imshow(T) # In[153]: np.sum(np.cumsum(T[10::-1,:],axis=0)>0,axis=0) # In[152]: 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)) # In[147]: plt.imshow(np.cumsum(T[10::-1,:],axis=0)>0,extent=[0,nx,0,10]) # In[143]: plt.imshow(np.cumsum(T[10:,:],axis=0)>0,extent=[0,nx,0,10]) # In[124]: plt.imshow(np.cumsum(b[::,:],axis=0)>0) # In[ ]: # In[ ]: # In[ ]: # In[ ]: