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 8174703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:31:48+00:00 2026-06-06T22:31:48+00:00

What I want to do is take my current array and subtract the previous

  • 0

What I want to do is take my current array and subtract the previous rows column value from the current rows column value. I also want to take the result and add it to the array as a new dimension.

Example Array:

[[1,2,4,7,9,15], [3, 4,3,5,10,2], [5,6,56,7,20,1]]

Lets say I want to do this with the 4th column so I want the output to be an array that looks like this:

[[1,2,4,7,9,15,0], [3, 4,3,5,10,2,-2], [5,6,56,7,20,1,2]]

Thanks

  • 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-06T22:31:48+00:00Added an answer on June 6, 2026 at 10:31 pm

    You can do this using a combination of np.diff, and concatenate options, like so:

    import numpy as np
    myarray = np.array([[1,2,4,7,9,15], [3, 4,3,5,10,2], [5,6,56,7,20,1]])
    #your differences appears to be wraparound, so we repeat the last row at the top:
    myarray_wrap = np.vstack((myarray[-1],myarray))
    #this gets the diffs for all columns:
    column_diffs = np.diff(myarray_wrap, axis=0)
    #now we add in only the the column_diff that we want, at the end:
    print np.hstack((myarray, column_diffs[:,3].reshape(-1,1)))
    #Output:
    [[ 1  2  4  7  9 15  0]
     [ 3  4  3  5 10  2 -2]
     [ 5  6 56  7 20  1  2]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to take the current key in the array. I know the function
I am trying to create a new array from two current arrays. Tried array_merge,
I want to take advantage of the new features in Windows 7 using C#
I want to take an array and use that array's values to populate an
I want to take an XML file and replace an element's value. For example
I want to take the current page's URL (using page:env(caller)) and extract a section
I want to take data from database and compare with system time.my android code
in c#, i want a function to take current date and return the number
Basically, I want to take my current Account.Balance and calculate interest once daily, based
I want to take multiple integer inputs in same line eg :- input -1

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.