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
Asked
Active
Viewed 391 times
-3
-
I don't get the downvotes. Not every question requires a code example to be clear and well posed. – roadrunner66 Apr 21 '16 at 00:52
-
@saguthegreat, welcome to Stack Overflow. – roadrunner66 Apr 21 '16 at 00:52
-
Ya seems pretty brutal out here. – saguthegreat Apr 21 '16 at 09:25
1 Answers
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]])

Taylan
- 736
- 1
- 5
- 14