I have a 2d array that looks like this:
XX
xx
What\'s the most efficient way to add an extra row and column:
xxy
xxy
yyy
>
I find it much easier to "extend" via assigning in a bigger matrix. E.g.
import numpy as np
p = np.array([[1,2], [3,4]])
g = np.array(range(20))
g.shape = (4,5)
g[0:2, 0:2] = p
Here are the arrays:
p
array([[1, 2],
[3, 4]])
g:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]])
and the resulting g after assignment:
array([[ 1, 2, 2, 3, 4],
[ 3, 4, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]])