0

I am having issues flatting the following matrix into an array

np.matrix([[1],
        [2],
        [3]])

More generally this matrix will be n,1 shape

The goal is to get it to be in a 3, form like [1, 2, 3] however I am finding that difficult. Every operation I can find returns a matrix or does not work.

x = np.matrix([[1],
        [2],
        [3]])
x.flatten()
>>>matrix([[1, 2, 3]])
x.ravel()
>>>matrix([[1, 2, 3]])
x.ravel()[0,:]
>>>matrix([[1, 2, 3]])
np.reshape(x, 3)
>>>matrix([[1, 2, 3]])
x.flatten()[0]
>>>matrix([[1, 2, 3]])

How can I get this one row-ed matrix into a vector?

J.Doe
  • 1,502
  • 13
  • 47

1 Answers1

2

You need to convert it to an array. Matrix objects are 2-dimensional by definition.

np.array(x).flatten()

Alternatively, as mentioned by @hpaulj, matrix objects have A and A1 defined that will return the array object (flattened for A1)

x.A1
busybear
  • 10,194
  • 1
  • 25
  • 42