Add an extra column to a NumPy array

In this python numpy program, we will add an extra column to a NumPy array.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Create another array of the same dimension as the given array.
  4. Add the new array as a column to the original array using np.append() and set the axis equal to 1 for the column.
  5. 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]]
				
			

convert an array of float values to an array of integer values.

replace the negative values in an array with 1.

Leave a Comment