目录

flatten

此函数返回折叠为一维的数组的副本。 该函数采用以下参数。

ndarray.flatten(order)

Where,

Sr.No. 参数和描述
1

order

'C' - 行主要(默认。'F':列主要'A':以列主要顺序展平,如果a是Fortran在内存中连续,则行主要顺序否则'K':按顺序压扁a发生在记忆中

例子 (Example)

import numpy as np 
a = np.arange(8).reshape(2,4) 
print 'The original array is:' 
print a 
print '\n'  
# default is column-major 
print 'The flattened array is:' 
print a.flatten() 
print '\n'  
print 'The flattened array in F-style ordering:' 
print a.flatten(order = 'F')

上述方案的产出如下 -

The original array is:
[[0 1 2 3]
 [4 5 6 7]]
The flattened array is:
[0 1 2 3 4 5 6 7]
The flattened array in F-style ordering:
[0 4 1 5 2 6 3 7]
↑回到顶部↑
WIKI教程 @2018