Numpy MaskedArray.flatten() function | Python Last Updated : 03 Oct, 2019 Comments Improve Suggest changes Like Article Like Report numpy.MaskedArray.flatten() function is used to return a copy of the input masked array collapsed into one dimension. Syntax : numpy.ma.flatten(order='C') Parameters: order : [‘C’, ‘F’, ‘A’, ‘K’, optional] Whether to flatten in C (row-major), Fortran (column-major) order, or preserve the C/Fortran ordering from a. The default is ‘C’. Return : [ ndarray] A copy of the input array, flattened to one dimension. Code #1 : Python3 # Python program explaining # numpy.MaskedArray.flatten() method # importing numpy as geek # and numpy.ma module as ma import numpy as geek import numpy.ma as ma # creating input array of 2 * 2 in_arr = geek.array([[10, 20], [-10, 40]]) print ("Input array : ", in_arr) # Now we are creating a masked array # by making one entry as invalid. mask_arr = ma.masked_array(in_arr, mask =[[ 1, 0], [ 0, 0]]) print ("Masked array : ", mask_arr) # applying MaskedArray.flatten methods to make # it a 1D flattened array out_arr = mask_arr.flatten() print ("Output flattened masked array : ", out_arr) Output: Input array : [[ 10 20] [-10 40]] Masked array : [[-- 20] [-10 40]] Output flattened masked array : [-- 20 -10 40] Code #2 : Python3 # Python program explaining # numpy.MaskedArray.flatten() method # importing numpy as geek # and numpy.ma module as ma import numpy as geek import numpy.ma as ma # creating input array in_arr = geek.array([[[ 2e8, 3e-5]], [[ -4e-6, 2e5]]]) print ("Input array : ", in_arr) # Now we are creating a masked array # by making one entry as invalid. mask_arr = ma.masked_array(in_arr, mask =[[[ 1, 0]], [[ 0, 0]]]) print ("Masked array : ", mask_arr) # applying MaskedArray.flatten methods to make # it a 1D masked array out_arr = mask_arr.flatten(order ='F') print ("Output flattened masked array : ", out_arr) Output: Input array : [[[ 2.e+08 3.e-05]] [[-4.e-06 2.e+05]]] Masked array : [[[-- 3e-05]] [[-4e-06 200000.0]]] Output flattened masked array : [-- -4e-06 3e-05 200000.0] Comment More infoAdvertise with us Next Article Numpy MaskedArray.flatten() function | Python jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads Numpy MaskedArray.any() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read Numpy MaskedArray.astype() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 2 min read Numpy MaskedArray.anom() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 2 min read Numpy MaskedArray.all() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays. Masked arrays are arr 3 min read Numpy MaskedArray.dot() function | Python numpy.MaskedArray.dot() function is used to calculate the dot product of two mask arrays. Syntax : numpy.ma.dot(arr1, arr2, strict=False) Parameters: arr1, arr2:[ ndarray] Inputs arrays. strict : [bool, optional] Whether masked data are propagated (True) or set to 0 (False) for the computation. Defa 3 min read Numpy MaskedArray.argmin() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read Numpy ndarray.flatten() function in Python The flatten() function is used to convert a multi-dimensional NumPy array into a one-dimensional array. It creates a new copy of the data so that original array stays unchanged. If your array has rows and columns or even more dimensions, then flatten() line up every single value into a straight list 3 min read Numpy MaskedArray.argsort() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read Numpy MaskedArray.average() function | Python numpy.MaskedArray.average() function is used to return the weighted average of array over the given axis. Syntax : numpy.ma.average(arr, axis=None, weights=None, returned=False) Parameters: arr :[ array_like] Input masked array whose data to be averaged. Masked entries are not taken into account in 3 min read Numpy MaskedArray.conjugate() function | Python numpy.MaskedArray.conjugate() function is used to return the complex conjugate, element-wise.The conjugate of a complex number is obtained by changing the sign of its imaginary part. Syntax : numpy.ma.conjugate(arr, out=None, where=True, casting='same_kind', order='K', dtype=None, subok=True)Paramet 2 min read Like