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
-
I don't get the downvotes. Not every question requires a code example to be clear and well posed.roadrunner66– roadrunner662016-04-21 00:52:01 +00:00Commented Apr 21, 2016 at 0:52
-
@saguthegreat, welcome to Stack Overflow.roadrunner66– roadrunner662016-04-21 00:52:30 +00:00Commented Apr 21, 2016 at 0:52
-
Ya seems pretty brutal out here.saguthegreat– saguthegreat2016-04-21 09:25:07 +00:00Commented Apr 21, 2016 at 9:25
Add a comment
|
1 Answer
>>> 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]])