# welcome to softhunt.net
# Python program explaining
# numpy.ndarray.flatten() function
# importing numpy as np
import numpy as np
arr = np.array([[2, 3], [4, 5]])
softhunt = arr.flatten()
print( softhunt )
>>> a = np.array([[1,2], [3,4]])
>>> a.flatten()
array([1, 2, 3, 4])
import numpy as np
List = np.array([[1,2,3], [4,5,6], [7,8,9]])
print(list(List.flat))
# welcome to softhunt.net
# Python Program illustrating
# working of ndarray.flat()
import numpy as np
# Working on 1D iteration of 2D array
array = np.arange(15).reshape(5, 3)
print("2D array :
",array )
# Using flat() : 1D iterator over range
print("
Using Array : ", array.flat[2:6])
# Using flat() to Print 1D represented array
print("
1D representation of array :
->", array.flat[0:15])
numpy.ndarray.flat()
numpy.ndarray.flatten(order=’C’)
# welcome to softhunt.net
# Python Program illustrating
# working of ndarray.flat()
import numpy as np
# Working on 1D iteration of 2D array
array = np.arange(15).reshape(5, 3)
print("2D array :
",array )
# All elements set to 1
array.flat = 1
print("
All Values set to 1 :
", array)
array.flat[3:6] = 8
array.flat[8:10] = 9
print("Changing values in a range :
", array)