numpy add new column

: import numpy as np
: N = 3
: A = np.eye(N)

: np.c_[ A, np.ones(N) ]              # add a column
array([[ 1.,  0.,  0.,  1.],
       [ 0.,  1.,  0.,  1.],
       [ 0.,  0.,  1.,  1.]])

Here is what the above code is Doing:
1. import numpy as np
2. N = 3
3. A = np.eye(N)
4. np.c_[ A, np.ones(N) ] # add a column

1. This line imports the numpy library as np.
2. This line sets the variable N to 3.
3. This line creates a 3×3 identity matrix using the numpy function eye().
4. This line adds a column of ones to the matrix A using the numpy function c_.

The c_ function is a convenience function that allows us to concatenate two arrays horizontally (i.e., add columns).

If we wanted to add a row of ones to A, we could use the r_ function:

: import numpy as np
: N = 3
: A = np.eye(N)

: np.r_[ A, np.ones(N) ] # add a row
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.],
[ 1., 1., 1.]])