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 :: Write a Python program to count the number of lines in a text file. 
Python :: feature importance naive bayes python 
Python :: delete tuple from list python 
Python :: heroku python buildpack 
Python :: delete key value in dictionary python 
Python :: get page title by python bs4 
Python :: python pygame how to start a game 
Python :: install fasttext python 
Python :: python how to get the folder name of a file 
Python :: python exam questions pdf 
Python :: python pyowm 
Python :: python get first character of string 
Python :: install different python version debian 
Python :: get token from request django 
Python :: levenshtein distance 
Python :: how to read multiple csv file from different directory in python 
Python :: pandas categorical to numeric 
Python :: tkinter simple notification 
Python :: try python import 
Python :: ValueError: Found array with dim 3. Estimator expected <= 2. 
Python :: decode multipart/form-data python 
Python :: python how to count items in array 
Python :: pandas groupby mean round 
Python :: breadth first search graph python 
Python :: python getattr 
Python :: how to set variable in flask 
Python :: python json check if key exists 
Python :: python pipe 
Python :: how to check if item is in the variable python 
Python :: python venv activate 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =