human
Can you provide a the Python program you requested given the following:
I am working on the file "QWZ.ipynb".
The first task is:
Finite sample - the potato argument
Finally we define a finite rectangular shaped lattice and than cut out a potato shaped region out of it and inspect the spectrum and the wavefunctions of this finite irregular sample.
Can you write Python program for it?
assistant
#Here is the Python program you requested.

class finite_lattice:
    '''
    Class for a generic 2D lattice.
    '''
    def __init__(self,xL=4,yL=3,**kwargs):
        '''
        Initializatin
        '''

        self.xL=xL
        self.yL=yL
        self.xran=arange(xL)
        self.yran=arange(yL)
        self.ym,self.xm=meshgrid(self.yran,self.xran)
        self.y,self.x=(self.ym.flatten(),self.xm.flatten())

    def make_ham(self,Tx,Ty,U,**kwargs):
        '''
        Make Hamiltonian for a square shape
        '''
        ODX=ssp.diags([ones(self.xL-1)],[1])
        DX =ssp.diags([ones(self.xL)],[0])
        ODY=ssp.diags([ones(self.yL-1)],[1])
        DY =ssp.diags([ones(self.yL)],[0])
        # internal degrees of freedom
        self.idf=shape(Tx)[0]   
        self.H=(ssp.kron(DX,ssp.kron(ODY,Ty))+
                ssp.kron(DX,ssp.kron(ODY,Ty)).H +
                ssp.kron(ODX,ssp.kron(DY,Tx))+
                ssp.kron(ODX,ssp.kron(DY,Tx)).H +
                ssp.kron(DX,ssp.kron(DY,U)) )
        
    def plot_fullwf(self,psi,**kwargs):
        '''
        Plotter for wavefunctions of the whole lattice.
        '''
        pcolor(self.xm,self.ym,
               reshape(sum(
                    reshape(abs(psi)**2,(self.xL*self.yL,self.idf)),
                    axis=1),(self.xL,self.yL)
                      ),**kwargs)

        
    def cut_potato(self,potx,poty,inverted=False,**kwargs):
        '''
        Make Hamiltonian for an arbitrary shape.
        We carve out the shape from the rectangle
        of the original lattice.
        '''
        potato=matplotlib.path.Path(array([potx,poty]).T)        
        self.potato_cindx=(potato.contains_points(
                           array([self.x,self.y]).T))
        self.potato_hindx=(potato.contains_points(
                           array([kron(self.x,ones(self.idf)),
                                  kron(self.y,ones(self.idf))]).T))
        if inverted:
            self.potato_cindx=logical_not(self.potato_cindx)
            self.potato_hindx=logical_not(self.potato_hindx)
       ...