numpy.ndarray.flatten
ndarray.flatten(order=’C’)
Return a copy of the array collapsed into one dimension.
Parameters:
order : {‘C’, ‘F’, ‘A’}, optional
Whether to flatten in row-major (C-style) or column-major (Fortran-style) order or preserve the C/Fortran ordering from a. 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])
本文详细介绍了如何使用numpy库中的ndarray.flatten方法将多维数组转换为一维数组,并展示了不同顺序参数对扁平化操作的影响。通过具体示例说明了C风格和Fortran风格的排列区别。
1130

被折叠的 条评论
为什么被折叠?



