-3

I would like to know if there is any easy way to append a column to an existing m x n Matrix and convert it to a m x (n+1) Matrix

3
  • I don't get the downvotes. Not every question requires a code example to be clear and well posed. Commented Apr 21, 2016 at 0:52
  • @saguthegreat, welcome to Stack Overflow. Commented Apr 21, 2016 at 0:52
  • Ya seems pretty brutal out here. Commented Apr 21, 2016 at 9:25

1 Answer 1

3
>>> array1 = np.array([[1,2,3],[4,5,6]])
>>> array1
array([[1, 2, 3],
       [4, 5, 6]])
>>> add = np.zeros((2,1), dtype=int64)
>>> add
array([[0],
       [0]])
>>> np.append(array1, add, axis=1)
array([[1, 2, 3, 0],
       [4, 5, 6, 0]])


>>> b=np.array([[6],[8]])
>>> np.append(array1,b,axis=1)
array([[1, 2, 3, 6],
       [4, 5, 6, 8]])
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.