Numpy MaskedArray asarray() method | Python
numpy.ma.asarray() function is used when we want to convert input to a masked array of the given data-type.
No copy is performed if the input is already a ndarray. If arr is a subclass of MaskedArray, a base class MaskedArray is returned.
Syntax : numpy.ma.asarray(arr, dtype=None, order=None)
arr : [array_like] Input data, in any form that can be converted to a masked array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists, ndarrays and masked arrays.
dtype : [data-type, optional] By default, the data-type is inferred from the input data.
order : Whether to use row-major (C-style) or column-major (Fortran-style) memory representation. Defaults to ‘C’.
Return : [MaskedArray] Masked array interpretation of arr.
Code #1 :
Input list : [1, 4, 8, 7, 2, 5] output array from input list : [1 4 8 7 2 5]
Code #2 :
Input touple : ([1, 4, 8], [7, 2, 5]) output array from input touple : [[1 4 8] [7 2 5]]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course