Numpy ndarray.flatten()函数| Python
numpy.ndarray.flatten()
函数返回折叠成一维的数组的副本。
Syntax : numpy.ndarray.flatten(order=’C’)
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’.
Return : [ndarray] A copy of the input array, flattened to one dimension.
代码#1:
# Python program explaining
# numpy.ndarray.flatten() function
# importing numpy as geek
import numpy as geek
arr = geek.array([[5, 6], [7, 8]])
gfg = arr.flatten()
print( gfg )
输出 :
[5 6 7 8]
代码#2:
# Python program explaining
# numpy.ndarray.flatten() function
# importing numpy as geek
import numpy as geek
arr = geek.array([[5, 6], [7, 8]])
gfg = arr.flatten('F')
print( gfg )
输出 :
[5 6 7 8]