Wednesday, July 3, 2024
HomeLanguagesPythonNumpy ndarray.flatten() function | Python

Numpy ndarray.flatten() function | Python

numpy.ndarray.flatten() function return a copy of the array collapsed into one dimension.

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.

Code #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 )


Output :

[5 6 7 8]

 
Code #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 )


Output :

[5 6 7 8]
Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments