Finding optimal weights for models
Also you have misunderstood the -1..
It's not the exponent rather the symbol of inverse of a Matrix 

Also use .T for Transpose...(a bit Pythonic Convenience)

Just to help you out,
Search np.linalg.inv

For your second Query,

Refer here

Just to add a little, you stop when you see that your loss isn't improving any more as such or is improving at the 5th decimal place..

Hope this helps..