Skip to main content
Removed historical information (that is what the revision history is for) - the answer should be as if it was written right now.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 

Edit 11/02/2016: OnlyIt only works when sublists have identical dimensions.

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 

Edit 11/02/2016: Only works when sublists have identical dimensions.

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 

It only works when sublists have identical dimensions.

added 72 characters in body
Source Link
mdh
  • 5.6k
  • 5
  • 32
  • 33

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 

Edit 11/02/2016: Only works when sublists have identical dimensions.

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 

Edit 11/02/2016: Only works when sublists have identical dimensions.

deleted 53 characters in body
Source Link
mdh
  • 5.6k
  • 5
  • 32
  • 33

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 

Performance:

import timeit timeit.Timer( 'import numpy as np; list(np.array(l).flat)', 'l=[[1, 2, 3], [4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7]] * 10000' ).timeit(100) 

0.31461596488952637

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 

Performance:

import timeit timeit.Timer( 'import numpy as np; list(np.array(l).flat)', 'l=[[1, 2, 3], [4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7]] * 10000' ).timeit(100) 

0.31461596488952637

One can also use NumPy's flat:

import numpy as np list(np.array(l).flat) 
added performance test
Source Link
mdh
  • 5.6k
  • 5
  • 32
  • 33
Loading
Source Link
mdh
  • 5.6k
  • 5
  • 32
  • 33
Loading