Link to home
Start Free TrialLog in
Avatar of dadadude
dadadude

asked on

convert matrix to vector python

hello i want to know how can we convert a matrix to a vector in python?

in matlab if i have a matrix a =  [[1 2 3];[4,5,6];[7,8,9]]
if i use a(:)
i will get :1
               2
               .
               .
              9
it's not working in python!!!
SOLUTION
Avatar of Superdave
Superdave
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dadadude
dadadude

ASKER

Actually i want to convert a 2D matrix into a vector:
your example worked but I was wondering if i can do that with numpy.
because later i have to calculate a - 1.
and it's not working with that method.
Do
b = a.flatten(1)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial