Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.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
Python 制作包含多维数组所有值的一维数组_Python_Arrays_Numpy_Multidimensional Array - Fatal编程技术网

Python 制作包含多维数组所有值的一维数组

Python 制作包含多维数组所有值的一维数组,python,arrays,numpy,multidimensional-array,Python,Arrays,Numpy,Multidimensional Array,我这样做的方式是: self.cleaned = [] for a in self.P[-1]: for b in a: for c in b: for d in c: self.cleaned.extend(d) 这是非常丑陋和不直观的,有没有一个适当的方式这样做?可能使用numpy您可以使用以下方法直接使用numpy展平: self.cleaned = np.array(self.P).flatten()

我这样做的方式是:

self.cleaned = []
for a in self.P[-1]:
    for b in a:
        for c in b:
            for d in c:
                self.cleaned.extend(d)

这是非常丑陋和不直观的,有没有一个适当的方式这样做?可能使用numpy

您可以使用以下方法直接使用numpy展平:

self.cleaned = np.array(self.P).flatten()