Numpy MaskedArray asarray() method | Python Last Updated : 16 Nov, 2021 Comments Improve Suggest changes Like Article Like Report 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) Parameters : 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 : Python3 # Python program explaining # numpy.ma.asarray() function import numpy as geek my_list = [1, 4, 8, 7, 2, 5] print ("Input list : ", my_list) out_arr = geek.ma.asarray(my_list) print ("output array from input list : ", out_arr) Output : Input list : [1, 4, 8, 7, 2, 5] output array from input list : [1 4 8 7 2 5] Code #2 : Python3 # Python program explaining # numpy.ma.asarray() function import numpy as geek my_tuple = ([1, 4, 8], [7, 2, 5]) print ("Input tuple : ", my_tuple) out_arr = geek.ma.asarray(my_tuple) print ("output array from input tuple : ", out_arr) Output : Input tuple : ([1, 4, 8], [7, 2, 5]) output array from input tuple : [[1 4 8] [7 2 5]] Comment More infoAdvertise with us Next Article Numpy MaskedArray asarray() method | Python sanjoy_62 Follow Improve Article Tags : Machine Learning Python-numpy python Python Numpy-Masked Array Practice Tags : Machine Learningpython Similar Reads Numpy MaskedArray asanyarray() method | Python numpy.ma.asanyarray() function is used when we want to convert input to a masked array, conserving subclasses. If arr is a subclass of MaskedArray, its class is conserved. No copy is performed if the input is already an ndarray. Syntax : numpy.ma.asanyarray(arr, dtype=None) Parameters : arr : [array 2 min read Python | Numpy MaskedArray.__mod__ What is a mask? A boolean array, used to select only certain elements for an operation Python3 # A mask example import numpy as np x = np.arange(5) print(x) mask = (x > 2) print(mask) x[mask] = -1 print(x) Output: [0 1 2 3 4] [False False False True True] [ 0 1 2 -1 -1] numpy.ma.MaskedArray class 2 min read Numpy MaskedArray.filled() method - Python numpy.MaskedArray.filled() function return a copy of self, with masked values filled with a given value. However, if there are no masked values to fill, self will be returned instead as an ndarray. Syntax : numpy.MaskedArray.filled(self, fill_value = None) Parameters : fill_value : [scalar, optional 2 min read Python | Numpy getmaskarray() method With the help of numpy.getmaskarray() method, we can get the masked matrix in the form numpy array which shows masked values by using numpy.getmaskarray() method. Syntax : numpy.getmaskarray(array) Return : Return masked values in the form of numpy array. Example #1 : In this example we can see that 1 min read Python | Numpy MaskedArray.__abs__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__abs__ operator we can find the absolute value of each and every element in an array. Suppose we have a values 31.74, with the help of MaskedArray.__abs_ 1 min read python | Numpy masked_equal() method With the help of numpy.ma.masked_equal() method, we can get the mask a value that in an array by using numpy.ma.masked_equal() method. Syntax : numpy.ma.masked_equal(array, value) Return : Return the array after removing mask value. Example #1 : In this example we can see that by using numpy.ma.mask 1 min read Python | Numpy MaskedArray.__ne__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__ne__ operator we can find that which element in an array is not equal to the value which is provided in the parameter. Syntax: numpy.MaskedArray.__ne__ 1 min read Python | Numpy MaskedArray.__and__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__and__ method we can get the elements that is anded by the value that is provided as a parameter. Syntax: numpy.MaskedArray.__and__ Return: Return self 1 min read Python | Numpy MaskedArray.__add__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__add__ we can add a particular value that is provided as a parameter in the MaskedArray.__add__() method. Value will be added to each and every element i 1 min read Python | Numpy MaskedArray.__mul__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__mul__ we can multiply a particular value that is provided as a parameter in the MaskedArray.__mul__() method. Syntax: numpy.MaskedArray.__mul__ Return: 1 min read Like