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

  • SEARCH
  • Home
  • 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 9267057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:27:40+00:00 2026-06-18T14:27:40+00:00

I have a numpy array a , a.shape=(17,90,144) . I want to find the

  • 0

I have a numpy array a, a.shape=(17,90,144). I want to find the maximum magnitude of each column of cumsum(a, axis=0), but retaining the original sign. In other words, if for a given column a[:,j,i] the largest magnitude of cumsum corresponds to a negative value, I want to retain the minus sign.

The code np.amax(np.abs(a.cumsum(axis=0))) gets me the magnitude, but doesn’t retain the sign. Using np.argmax instead will get me the indices I need, which I can then plug into the original cumsum array. But I can’t find a good way to do so.

The following code works, but is dirty and really slow:

max_mag_signed = np.zeros((90,144))
indices = np.argmax(np.abs(a.cumsum(axis=0)), axis=0)
for j in range(90):
    for i in range(144):
        max_mag_signed[j,i] = a.cumsum(axis=0)[indices[j,i],j,i]

There must be a cleaner, faster way to do this. Any ideas?

  • 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-18T14:27:41+00:00Added an answer on June 18, 2026 at 2:27 pm

    I can’t find any alternatives to argmax but at least you can fasten that with a more vectorized approach:

    # store the cumsum, since it's used multiple times
    cum_a = a.cumsum(axis=0)
    
    # find the indices as before
    indices = np.argmax(abs(cum_a), axis=0)
    
    # construct the indices for the second and third dimensions
    y, z = np.indices(indices.shape)
    
    # get the values with np indexing
    max_mag_signed = cum_a[indices, y, z]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a numpy array, a , a.shape=(48,90,144) . I want to take the
I have a numpy array A such that A.shape[axis] = n+1. Now I want
I have a NumPy array, i want to accumulate the values of one column,
I have a NumPy array [1,2,3,4,5,6,7,8,9,10,11,12,13,14] and want to have an array structured like
I have a numpy array like this a = np.array(1) Now if I want
I have a 2D numpy array of shape (N,2) which is holding N points
I have a numpy array of shape (height, width, 3) loaded from an image.
I currently have a numpy multi-dimensional array (of type float) and a numpy column
I have an image, stored in a numpy array of uint8 s, of shape
I have a 2D numpy array that I want to plot in a colorbar.

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.