In this python numpy program, we will add an extra column to a NumPy array.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Create another array of the same dimension as the given array.
- Add the new array as a column to the original array using np.append() and set the axis equal to 1 for the column.
- Print the output.
import numpy as np
x = np.array([[4,8,0],[2,0,6]])
y = np.array([[5],[7]])
print(np.append(x, y, axis=1))
Output :
[[4 8 0 5]
[2 0 6 7]]