0

I would like to add a row into a 1-D array with a 2-D array as a result:

import numpy as np
a = np.random.random((3,4))
b = np.array([1,2,3])
c = np.append(b, np.transpose(a[:,2]), axis=0)

But the result is a 1-D array:

array([ 1.        ,  2.        ,  3.        ,  0.77329384,  0.25485223,
    0.56982045])

How can I get the expected result:

array([1. , 2. , 3.  ,],
      [0.77329384, 0.25485223, 0.56982045])

Thanks in advance!

0

1 Answer 1

1
>>> np.vstack((b, np.transpose(a[:,2])))
array([[ 1.        ,  2.        ,  3.        ],
       [ 0.14942441,  0.75303451,  0.64617275]])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.