GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — NumPy Masked Arrays: Exercises and Solutions

  • Home
  • Python Home
  • Python Exercises
  • ▼Python NumPy
  • NumPy Home
  • ▼Basic Operations and Arrays
  • NumPy Basic
  • NumPy Array
  • ▼Mathematics, Linear Algebra, and Statistics
  • NumPy Mathematics
  • NumPy Linear Algebra
  • NumPy Statistics
  • ▼Random Numbers
  • NumPy Random
  • ▼Sorting, Searching, and Indexing
  • Sorting and Searching
  • NumPy Advanced Indexing
  • ▼Datetime and String Operations
  • NumPy DateTime
  • NumPy String
  • ▼Broadcasting and Memory Layout
  • NumPy Broadcasting
  • NumPy Memory Layout
  • ▼Performance Optimization and Interoperability
  • NumPy Performance Optimization
  • NumPy Interoperability
  • ▼Input/Output (I/O) Operations
  • NumPy I/O Operations
  • ▼Functions and Masked Arrays
  • NumPy Universal Functions
  • NumPy Masked Arrays
  • ▼Structured Arrays and SciPy Integration
  • NumPy Structured Arrays
  • NumPy Integration with SciPy
  • ▼Advanced Topics and Mastery
  • Advanced NumPy
  • Mastering Numpy
  • ..More to come..

NumPy Masked Arrays: Exercises and Solutions

Last update on April 30 2025 12:55:02 (UTC/GMT +8 hours)


This resource offers a total of 100 NumPy Masked Arrays problems for practice. It includes 20 main exercises, each accompanied by solutions, detailed explanations, and four related problems.

The following exercises focus on NumPy masked arrays, covering creation, modification, arithmetic operations, and data extraction while handling missing or excluded values efficiently. They help in performing computations while ignoring masked elements, making them essential for data analysis and preprocessing.

[An Editor is available at the bottom of the page to write and execute the scripts.]


1. Masked Array Creation

Write a NumPy program that creates a masked array from a regular NumPy array with some specified values masked.

Click me to see the sample solution


2. Masked Array Fill

Write a NumPy program that creates a masked array and fills the masked values with a specified number.

Click me to see the sample solution


3. Mean of Masked Array

Write a NumPy program to compute the mean of a masked array, ignoring the masked values.

Click me to see the sample solution


4. Mask Elements Greater Than Specified Value

Write a NumPy program that creates a masked array where all elements greater than a specified value are masked.

Click me to see the sample solution


5. Replace Masked Values with Mean

Write a NumPy program to replace all masked values in a masked array with the mean of the unmasked elements.

Click me to see the sample solution


6. Count Masked Elements

Write a NumPy program to create a masked array and count the number of masked elements.

Click me to see the sample solution


7. Element-wise Addition of Masked Arrays

Write a NumPy program to perform element-wise addition of two masked arrays, maintaining the masks.

Click me to see the sample solution


8. Mask a Specified Row in a 2D Array

Write a NumPy program to create a masked array from a 2D NumPy array and mask all values in a specified row.

Click me to see the sample solution


9. Logical Condition Masking

Write a NumPy program that creates a masked array and uses logical operations to mask elements based on a condition.

Click me to see the sample solution


10. Maximum Value in Masked Array

Write a NumPy program to create a masked array and find the maximum value, ignoring the masked elements.

Click me to see the sample solution


11. Indices of Unmasked Elements

Write a NumPy program to create a masked array and find the indices of all unmasked elements.

Click me to see the sample solution


12. Convert Masked Array to Regular Array

Write a NumPy program to create a masked array and convert it back to a regular NumPy array, replacing the masked values with NaN.

Click me to see the sample solution


13. Masked Operation: Multiplication

Write a NumPy program that creates a masked array and performs a masked operation, such as masked multiplication.

Click me to see the sample solution


14. Apply Custom Function to Unmasked Elements

Write a NumPy program that creates a masked array and applies a custom function only to the unmasked elements.

Click me to see the sample solution


15. Extract Unmasked Data

Write a NumPy program that creates a masked array and extracts the unmasked data as a regular NumPy array.

Click me to see the sample solution


16. Masked Sum Operation

Write a NumPy program to create a masked array and perform a masked sum operation, ignoring the masked elements.

Click me to see the sample solution


17. Masked Array with Complex Condition

Write a NumPy program that creates a masked array from a regular array and mask values based on a complex condition.

Click me to see the sample solution


18. Modify Existing Mask

Write a NumPy program that creates a masked array and changes the mask to include additional elements.

Click me to see the sample solution


19. Apply Math Function on Unmasked Elements

Write a NumPy program that creates a masked array and applies a mathematical function (e.g., sin, cos) only to the unmasked elements.

Click me to see the sample solution


20. Check for Presence of Masked Elements

Write a NumPy program that creates a masked array and checks if any masked elements are present.

Click me to see the sample solution


Python-Numpy Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.