python——flatten函数

    def flatten(self, order='C'): # real signature unknown; restored from __doc__
        """
        a.flatten(order='C')
        
            Return a copy of the array collapsed into one dimension.
        
            Parameters
            ----------
            order : {'C', 'F', 'A', 'K'}, optional
                'C' means to flatten in row-major (C-style) order.
                'F' means to flatten in column-major (Fortran-
                style) order. 'A' means to flatten in column-major
                order if `a` is Fortran *contiguous* in memory,
                row-major order otherwise. 'K' means to flatten
                `a` in the order the elements occur in memory.
                The default is 'C'.
        
            Returns
            -------
            y : ndarray
                A copy of the input array, flattened to one dimension.
        
            See Also
            --------
            ravel : Return a flattened array.
            flat : A 1-D flat iterator over the array.
        
            Examples
            --------
            >>> a = np.array([[1,2], [3,4]])
            >>> a.flatten()
            array([1, 2, 3, 4])
            >>> a.flatten('F')
            array([1, 3, 2, 4])
        """
        pass

optional
               'C' means to flatten in row-major (C-style) order.
                'F' means to flatten in column-major (Fortran-
                style) order. 'A' means to flatten in column-major
                order if `a` is Fortran *contiguous* in memory,
                row-major order otherwise. 'K' means to flatten
                `a` in the order the elements occur in memory.
                The default is 'C'.

可选择的

“C”表示按行大调(C风格)顺序展平。

“F”表示在大调(Fortran)列中变平-

(风格)秩序。”“A”表示在大调中变平

如果'a'在内存中是Fortran*连续的,

否则,请按主要顺序排列。”K的意思是变平

`按元素在内存中出现的顺序排列。

默认值为“C”。

  Examples
            --------
            >>> a = np.array([[1,2], [3,4]])
            >>> a.flatten()
            array([1, 2, 3, 4])
            >>> a.flatten('F')
            array([1, 3, 2, 4])

总结:flatten函数将多维矩阵转换成1*列数的矩阵,例如1*4,1*8矩阵


版权声明:本文为weixin_53660567原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。