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])
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])
python convert two dimensional list to one dimensional
# Python convert 2D into 1D array:
import itertools
x = [['foo'], ['bar', 'baz'], ['quux'], ("tup_1", "tup_2"), {1:"one", 2:"two"}]
print list(itertools.chain(*x))
print [element for sub in x for element in sub]
# Output:
['foo', 'bar', 'baz', 'quux', 'tup_1', 'tup_2', 1, 2]
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