Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flatten a list using numpy and itertools

import itertools
L1 = [[1, 2, 3, 4,20,30,40], [5, 6, 7,99,97,98], [81, 9, 100]]
flat_list = list(itertools.chain(*L1))
print(sorted(flat_list))
[1, 2, 3, 4, 5, 6, 7, 9, 20, 30, 40, 81, 97, 98, 99, 100]

import numpy
L1 = [[1, 2, 3, 4,20,30,40], [5, 6, 7,99,97,98], [81, 9, 100]]
flat_list = list(numpy.concatenate(L1).flat)
print(sorted(flat_list))
[1, 2, 3, 4, 5, 6, 7, 9, 20, 30, 40, 81, 97, 98, 99, 100]
Comment

PREVIOUS NEXT
Code Example
Python :: turn dictionary into flat list 
Python :: simple tower of hanoi project python with gui 
Python :: taking str input in python and counting no of it 
Python :: mock connection sqlalchemy 
Python :: pandas dataframe limit rows by col value 
Python :: Python pattern of 1010101 
Python :: Remove Brackets from List Using join method 
Python :: extract numbers from image python 
Python :: server localhost for shar file 
Python :: parameter name in string 
Python :: pygame borders on window 
Python :: python random number between 1000 and 9999 
Python :: loop regex 
Python :: dimensions of dataset in python 
Python :: load SQLite db into memory 
Python :: Flask_SQLAlchemy is claiming my value is not boolean 
Python :: How to solve import errors while trying to deploy Flask using WSGI on Apache2 
Python :: Python (cpython 2.7.16) sample 
Python :: linkedin bot python 
Python :: ring Do Again Loop 
Python :: found django install path 
Python :: gfxdraw circle weight 
Python :: Window freezes after clicking of button in python GTK3 
Python :: How to make exit button? 
Python :: regression avec sklearn best 
Python :: ax text relative coordinates 
Python :: where are dictd dictionaries 
Python :: Obtener el valor ASCII de un carácter en Python 
Python :: delete all historical data django simple history 
Python :: gizeh python 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =