Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 我使用嵌套while循环从列表中提取元素的更快的替代方法是什么?_Performance_Python 2.7_Nested Loops - Fatal编程技术网

Performance 我使用嵌套while循环从列表中提取元素的更快的替代方法是什么?

Performance 我使用嵌套while循环从列表中提取元素的更快的替代方法是什么?,performance,python-2.7,nested-loops,Performance,Python 2.7,Nested Loops,我使用下面提到的代码从List2中提取元素,并创建一个新的列表坐标。我正在寻找更好的方法使它更快 while m<(Length1 - 4) : j = 0 while j<3 : l = 0 while l<3 : Coordinates[i]= List2[m] l = l+1 m = m+1 i = i+1

我使用下面提到的代码从
List2
中提取元素,并创建一个新的列表坐标。我正在寻找更好的方法使它更快

while m<(Length1 - 4) :

    j = 0

    while j<3 :

        l = 0

        while l<3 :

            Coordinates[i]= List2[m]
            l = l+1
            m = m+1
            i = i+1


        m = m+1
        j = j+1

    m = m+9

我想你的问题需要澄清一下。但是一个词的答案是:numpyth列表2同时包含字符串和数字字符串。numpy有用吗?是的。首先,您可以使用numpy(实际上)消除循环的成本,并提高所述循环的表达能力。如果字符串的长度是固定的,那么在字符串处理过程中也会得到很大的加速。如果没有,您仍然可以使用object类型的numpy数组来处理strings,但是为了获得最干净的numpy解决方案,我认为您的问题需要更多的上下文。如果对您的问题有正确的了解,您可以在O(1)时间内将坐标表示为列表2上的视图和一行代码