Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:22:17+00:00 2026-06-13T04:22:17+00:00

How do I take the standard deviation under a mask along a specific axis

  • 0

How do I take the standard deviation under a mask along a specific axis in a numpy array?

data = array([[ 0,  1,  2,  3,  4],
              [ 5,  6,  7,  8,  9],
              [10, 11, 12, 13, 14],
              [15, 16, 17, 18, 19],
              [20, 21, 22, 23, 24]])

M = array([[0, 1, 0, 0, 0],
           [1, 1, 1, 1, 1],
           [1, 1, 0, 1, 1],
           [0, 0, 1, 0, 0],
           [0, 0, 0, 0, 0]])

The result array should be:

masked_std = std( data, axis=0, mask=M )
[ std([5,10]), std([1,6,11]), std([7,17]), std([8,13], std([9,14]) ]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:22:18+00:00Added an answer on June 13, 2026 at 4:22 am

    You can use a numpy masked array:

    In [19]: from numpy import ma
    
    In [20]: data
    Out[20]: 
    array([[ 0,  1,  2,  3,  4],
           [ 5,  6,  7,  8,  9],
           [10, 11, 12, 13, 14],
           [15, 16, 17, 18, 19],
           [20, 21, 22, 23, 24]])
    
    In [21]: M
    Out[21]: 
    array([[0, 1, 0, 0, 0],
           [1, 1, 1, 1, 1],
           [1, 1, 0, 1, 1],
           [0, 0, 1, 0, 0],
           [0, 0, 0, 0, 0]])
    
    In [22]: mdata = ma.masked_array(data, mask=~M.astype(bool))
    
    In [23]: mdata
    Out[23]: 
    masked_array(data =
     [[-- 1 -- -- --]
     [5 6 7 8 9]
     [10 11 -- 13 14]
     [-- -- 17 -- --]
     [-- -- -- -- --]],
                 mask =
     [[ True False  True  True  True]
     [False False False False False]
     [False False  True False False]
     [ True  True False  True  True]
     [ True  True  True  True  True]],
           fill_value = 999999)
    
    
    In [24]: mdata.std(axis=0)
    Out[24]: 
    masked_array(data = [2.5 4.08248290464 5.0 2.5 2.5],
                 mask = [False False False False False],
           fill_value = 999999)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most functions for generating lognormally distributed random numbers take the mean and standard deviation
I need to take standard incoming urls and rewrite redirect them to target specific
I'm trying to take a stream of data from standard in, compress it one
I am working to take the output of sar and calculate the standard deviation
Take the standard return statement for a controller: return View(Index); is there a way
All I am trying to do is take a standard range on an excel
Is there a standard C function similar to strtol which will take a char*
I'm trying to use a standard Intent that will take a picture, then allow
I'd like to take text from a standard text file and insert it into
I'm trying to take a xml document and transform to a standard html list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.