Python numpy easier syntax?
Question: I am new to numpy, and I'm already a little sick of its syntax.

Something which could be written like this in Octave/matlab

    
    
    1/(2*m) * (X * theta - y)' * (X*theta -y)
    

Becomes this in numpy

    
    
    np.true_divide(((X.dot(theta)-y).transpose()).dot((X.dot(theta)-y)),2*m)
    

This is much harder for me to write and debug. Is there any better way to
write matrix operations like above so as to make life easier?


Answer: You can make some simplifications. By using `from __future__ import division`
at the beginning of your program, all division will automatically be "true"
division, so you won't need to use `true_divide`. (In Python 3 you don't even
need to do this, since true division is automatically the default.) Also, you
can use `.T` instead of `.transpose()`. Your code then becomes

    
    
    1/(2*m) * ((X.dot(theta) - y).T).dot((X.dot(theta) - y))
    

which is a bit better.

In Python 3.5, a new matrix multiplication operator `@` is being added for
basically this exact reason. This is not out yet, but when it is (and when
numpy is updated to make use of it), your code will become very similar to the
Octave version:

    
    
    1/(2*m) * (X@theta - y).T @ (X@theta - y)
    

