NumPy 中的 flatten函数

首页 / Numpy入门教程 / NumPy 中的 flatten函数

此函数返回折叠成一维的数组,该函数采用以下参数。

ndarray.flatten(order)
Sr.No.  描述
1

order

链接:https://www.learnfk.comhttps://www.learnfk.com/numpy/numpy-ndarray-flatten.html

来源:LearnFk无涯教程网

'C'-行主(默认。'F':列'A':以列顺序进行展平,如果a在内存中是连续的Fortran,则为行主顺序,否则'K':按元素顺序进行展平发生在内存中

无涯教程网

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]

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

SQL必知必会 -〔陈旸〕

高并发系统设计40问 -〔唐扬〕

说透中台 -〔王健〕

Netty源码剖析与实战 -〔傅健〕

NLP实战高手课 -〔王然〕

Service Mesh实战 -〔马若飞〕

Selenium自动化测试实战 -〔郭宏志〕

Linux内核技术实战课 -〔邵亚方〕

容量保障核心技术与实战 -〔吴骏龙〕

好记忆不如烂笔头。留下您的足迹吧 :)