Answers for "example of how to flatten a 2D vector in python and numpy"

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

Python Answers by Framework

Browse Popular Code Answers by Language