Answers for "python flattern to 2d array"

1

flatten a 2d array python

arr_2d = [[1, 2, 3], [4, 5, 6]]
arr_1d = [el for arr in arr_2d for el in arr]
print(arr_1d) # [1, 2, 3, 4, 5, 6]
Posted by: Guest on May-18-2021
1

python convert multidimensional array to one dimensional

In [12]: a = np.array([[1,2,3], [4,5,6]])

In [13]: b = a.ravel()

In [14]: b
Out[14]: array([1, 2, 3, 4, 5, 6])
Posted by: Guest on March-04-2021

Python Answers by Framework

Browse Popular Code Answers by Language