Related Articles

# Numpy MaskedArray asanyarray() method | Python

• Last Updated : 17 Feb, 2020

`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_like] Input data, in any form that can be converted to a masked array.
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ā.

Code #1 :

 `# Python program explaining``# numpy.ma.asanyarray() function``import` `numpy as geek``my_list ``=` `[``1``, ``4``, ``8``, ``7``, ``2``, ``5``]`` ` `print` `(``"Input list : "``, my_list)`` ` ` ` `out_arr ``=` `geek.ma.asanyarray(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 :

 `# Python program explaining``# numpy.ma.asanyarray() function`` ` `import` `numpy as geek`` ` `my_tuple ``=` `([``1``, ``4``, ``8``], [``7``, ``2``, ``5``])`` ` `print` `(``"Input touple : "``, my_tuple)`` ` `out_arr ``=` `geek.ma.asanyarray(my_tuple) ``print` `(``"output array from input touple : "``, out_arr) `

Output :

```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

My Personal Notes arrow_drop_up