>>> import numpy as np
>>> m = np.array([[0,1,0],[0,0,1],[1,0,0]])
>>> v = np.array([2,3,1])
>>> np.linalg.solve(m,v)
array([ 1., 2., 3.])
No need to transpose, as numpy handles row and column vectors identically. Using the above variables `m` and `v`: >>> v @ m # treated as row vector
array([1, 2, 3])
>>> m @ v # treated as column vector
array([3, 1, 2])
Where `@`, for those who don't know, is the matrix multiplication operator (`np.dot`) introduced in recent versions of python 3.Exactly.
Python 3.5 was the first version of python3 to implement the PEP: https://docs.python.org/3.5/whatsnew/3.5.html
If I am reading the release notes correctly, Python 3.5.0 was released last year (2015-09-13): https://www.python.org/downloads/release/python-350/
It's fair to say that this is a relatively new development.
I mean in the context as @sampo described it above ...
In the Stanford/Coursera machine learning class, Andrew Ng said that his teaching experience is that students pick up octave/matlab quicker and the course can cover more actual machine learning, compared to python where more time is spent learning the language.
Then "which version of Python, and how is that different..." etc.
is there something wrong with numpys convenience method for transpose but not matlabs postfix unary convenience operator?
Also you too made the same mistake: np.array([2,3,1]).T doesn't do anything, you need np.array([[2,3,1]]).T
[1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.t...
When someone googles Matlab/Octave there won't be the same mixture of contexts as there is for Python. With Python there's "2 or 3?" before even starting. Than Cython or Jython or PyPy? That's nothing against Python except that in one particular time limited context, the questions are a distraction {without even considering the complaints of students when the choice of Python implementation is contrary to their opinion}.
m = matrix([[0, 1, 0],
[0, 0, 1],
[1, 0, 0]])
v = vector([2, 3, 1])
m \ v
(1, 2, 3)and then
sol = m \ v
m * sol
(2, 3, 1) m = matrix( c(0,0,1,1,0,0,0,1,0), nrow=3 )
v = c(2,3,1)
solve(m,v)
[1] 1 2 3
Julia: for this code snippet the syntax is identical to Matlab: m = [0 1 0; 0 0 1; 1 0 0]
v = [2 3 1]'
m\v
3×1 Array{Float64,2}:
1.0
2.0
3.0
Octave:
Python: If you just want to play around, Python has more clutter and gotchas.Of course, when you start to write real software, then the tools that Python provides for organizing your code start to weight more and the clumsiness of np.linalg.solve(m,v) over m\v starts to weight less.
But I can see how a 50-line testing script in Octave organically grows to a 2000-line application, and then it's already a lot of work to rewrite in Python.
Edit: a reply below makes a good point simplifying the Python code a little bit.