Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
Python | Numpy MaskedArray.__abs__
Next article icon

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 :




# 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 :




# 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]]    


Next Article
Python | Numpy MaskedArray.__abs__
author
sanjoy_62
Improve
Article Tags :
  • Machine Learning
  • python
  • Python Numpy-Masked Array
  • Python-numpy
Practice Tags :
  • Machine Learning
  • python

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 # 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 is a su
    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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences