convert 2d list to 1d python
import itertools
a = [[1, 2], [3, 4], [5, 6]]
list(itertools.chain.from_iterable(a))
Output:- [1, 2, 3, 4, 5, 6]
convert 2d list to 1d python
import itertools
a = [[1, 2], [3, 4], [5, 6]]
list(itertools.chain.from_iterable(a))
Output:- [1, 2, 3, 4, 5, 6]
2d to 1d array python
import numpy as np
ini_array1 = np.array([[1, 2, 3], [2, 4, 5], [1, 2, 3]])
result = ini_array1.flatten()
pass 2d array to 1d python
# Create a 2D Numpy Array.
arr = np. array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
# convert 2D array to a 1D array of size 9.
flat_arr = np. reshape(arr, 9)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us