📜  Numpy ndarray.flatten()函数| Python

📅  最后修改于: 2022-05-13 01:55:03.578000             🧑  作者: Mango

Numpy ndarray.flatten()函数| Python

numpy.ndarray.flatten()函数返回折叠成一维的数组的副本。

代码#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]