Answers for "numpy flat array 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
0

flat numpy array

>>> a = np.array([[1,2], [3,4]])
>>> a.flatten()
array([1, 2, 3, 4])
Posted by: Guest on July-22-2021

Python Answers by Framework

Browse Popular Code Answers by Language