9951 explained code solutions for 126 technologies


python-numpyHow to flatten multi-dimensional Numpy array


import numpy as np

a = np.array([[1, 2], [3, 4]])
f = a.flatten()ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

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

sample matrix data (2-dimensional array)

.flatten()

returns flat 1-dimensional array from given multi-dimensional array