9951 explained code solutions for 126 technologies


python-numpyHow to get last column from Numpy array


import numpy as np
arr = np.array([[1, 2], [3, 4]])
row = arr[:,-1]ctrl + c
import numpy as np

load Numpy module for Python

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

sample matrix data (2-dimensional array)

np.array

declare Numpy array

arr

variable contains array

[:,-1]

return last column of a given matrix