Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT: Here's some actual numbers! The <code>izip</code>, list comprehension, and <code>numpy</code> ways of doing this are all about the same speed.</p> <pre><code># zip &gt;&gt;&gt; timeit.timeit( "newlist = zip(*someList)[0]", setup = "someList = [range(1000000), range(1000000), range(1000000)]", number = 10 ) 1.4984046398561759 # izip &gt;&gt;&gt; timeit.timeit( "newlist = izip(*someList).next()", setup = "someList = range(1000000), range(1000000), range(1000000)]; from itertools import izip", number = 10 ) 2.2186223645803693e-05 # list comprehension &gt;&gt;&gt; timeit.timeit( "newlist = [li[0] for li in someList]", setup = "someList = [range(1000000), range(1000000), range(1000000)]", number = 10 ) 1.4677040212518477e-05 # numpy &gt;&gt;&gt; timeit.timeit( "newlist = someList[0,:]", setup = "import numpy as np; someList = np.array([range(1000000), range(1000000), range(1000000)])", number = 10 ) 6.6217344397045963e-05 &gt;&gt;&gt; </code></pre> <hr> <p>For large data structures like this you should use <a href="http://numpy.scipy.org/" rel="noreferrer"><code>numpy</code></a>, which implementes an array type in C and hence is significantly more efficient. It also provides all the matrix manipulation you will ever want.</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; foo = np.array([[0,1,2],[3,4,5],[6,7,8]]) &gt;&gt;&gt; foo[:,0] array([0, 3, 6]) </code></pre> <p>You can also transpose...</p> <pre><code>&gt;&gt;&gt; foo.transpose() array([[0, 3, 6], [1, 4, 7], [2, 5, 8]]) </code></pre> <p>...work with n-dimensional arrays...</p> <pre><code>&gt;&gt;&gt; foo = np.zeros((3,3,3)) &gt;&gt;&gt; foo array([[[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]], [[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]], [[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]]) &gt;&gt;&gt; foo[0,...] array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]) </code></pre> <p>..do efficient linear algebra...</p> <pre><code>&gt;&gt;&gt; foo = no.ones((3,3)) &gt;&gt;&gt; np.linalg.qr(foo) (array([[-0.57735027, 0.81649658, 0. ], [-0.57735027, -0.40824829, -0.70710678], [-0.57735027, -0.40824829, 0.70710678]]), array([[ -1.73205081e+00, -1. 73205081e+00, -1.73205081e+00], [ 0.00000000e+00, -1.57009246e-16, -1.57009246e-16], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]])) </code></pre> <p>...and basically do <a href="http://mathesaurus.sourceforge.net/matlab-numpy.html" rel="noreferrer">anything that Matlab can</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload