9951 explained code solutions for 126 technologies


python-numpyHow to add column to Numpy array


import numpy as np
arr = np.array([[1, 2], [3, 4]])
arr = np.append(arr, [[5], [6]], axis=1)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

[[1, 2], [3, 4]]

sample 2-dimensional array to add new column to

np.append

append values to specified array

arr

array to append column to

[[5], [6]]

new column values to append

axis=1

append new values along vertical (1) axis