I need to find the equivalent from matlab of A(:) in python. Where A is a matrix(m,n):
For example:
A =
5 6 7
8 9 10
A(:)
ans =
5
8
6
9
7
10
thanks in advance!
I need to find the equivalent from matlab of A(:) in python. Where A is a matrix(m,n):
For example:
A =
5 6 7
8 9 10
A(:)
ans =
5
8
6
9
7
10
thanks in advance!
If you want the column-major result (to match the Matlab convention), you probably want to use the transpose of your numpy
matrix, and then the ndarray.ravel()
method:
m = numpy.array([[ 5, 6, 7 ], [ 8, 9, 10 ]])
m.T.ravel()
which gives:
array([ 5, 8, 6, 9, 7, 10])
You can do this by reshaping your array with numpy.reshape
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.reshape.html
import numpy
m = numpy.array([[ 5, 6, 7 ], [ 8, 9, 10 ]])
print(numpy.reshape(m, -1, 'F'))