Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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])
Comment

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]

Comment

PREVIOUS NEXT
Code Example
Python :: python check if string in string 
Python :: timer in python 
Python :: python script to scrape data from website 
Python :: python read excel 
Python :: how to append panda columns using loop 
Python :: get local ip 
Python :: integral python 
Python :: time difference between two datetime.time 
Python :: concatenating datfra,esin pandas 
Python :: python dictonary set default 
Python :: find all occurrences of an element in a list python 
Python :: determinant of matrix in python 
Python :: python generate pdf from template 
Python :: thread syntax in python 
Python :: python count how many times a character appears in a string 
Python :: itertools .cycle() 
Python :: SciPy Convex Hull 
Python :: python dict remove duplicates where items are not the same 
Python :: graph a line from dataframe values over a bar plot in python 
Python :: python substring from end 
Python :: python delete all occurrences from list 
Python :: Filter with List Comprehension 
Python :: counter +1 python 
Python :: static files in django 
Python :: queryset to list python 
Python :: convert a text file data to dataframe in python without pandas 
Python :: dense layer keras 
Python :: get UTC time for IST time python 
Python :: python add attribute to class instance 
Python :: sentence transformers 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =