When I multiply an nxn matrix by a nx1 vector, I get back a nested vector. How do I avoid this or how do I recover the vector.
Examples:
Using @ operator
A = np.matrix([[1,4,3],[2,2,1],[5,4,2]]) v = np.array([1,2,3]) A @ v => RuntimeError: Iterator automatic output has an array subtype which changed the dimensions of the output Using np.dot
np.dot(A,v) => matrix([[18,9,19]]) Here the vector is nested and is a matrix of shape (3,1). I just want a vector of length 3 (i.e. of shape (3,))
If I had declared the matrix as an array, using the @ operator would've worked just fine, but I can't do this for this homework exercise.
np.matrixis ALWAYS 2d. And these math operations usingnp.matrixreturnnp.matrix, even if the other argument isndarray. You can use.A1to return a 1dndarrayfrom anp.matrix:np.dot(A,v).A1.np.matrix? Read the docs. Developers would like us to stop using it. I"m closing this because thematrix to arrayconversion has already been covered.