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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:57:07+00:00 2026-06-14T11:57:07+00:00

I have a simple function called get_gradient which takes a numpy array of [[x,y,Vx,Vy]]

  • 0

I have a simple function called get_gradient which takes a numpy array of [[x,y,Vx,Vy]] and returns (should return) an array of [[Vx,Vy,Ax,Ay]]. I want to update my k[0][0:2] to equal state[0][2:4] but when I print them out k never changes value. I created a copy of the initial array in the hope that it would sort it out but it still doesn’t work! any help would be much appreciated

Y          = numpy.array([[0, 0, 0, 0]]) # [x,y,Vx,Vy]
k          = numpy.array([[0, 0, 0, 0]]) # [x,y,Vx,Vy]

def get_gradient(Y):
    state = Y.copy()
    spring_force   = spring.force(state[0], feet_pos[0])
    brownian_force = mass.brownian(dt)
    drag_force     = mass.drag(state[0][2:4])
    total_force    = spring_force + brownian_force + drag_force     #2d array [Fx,Fy]

    k[0][0:2] = state[0][2:4]            ##### DOESN'T WORK!!!
    k[0][2:4] = total_force/mass.mass    ##### but this works :s

    print k[0][0:2]
    print state[0][2:4]

    return k
  • 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-14T11:57:08+00:00Added an answer on June 14, 2026 at 11:57 am

    It’s not that k isn’t changing, it’s that it has an integer dtype, and so when you try to assign a float to it, you might not get what you expect:

    >>> k
    array([[   0,    0, 4863, 1464]])
    >>> k.dtype
    dtype('int64')
    >>> k[0][0] = 10
    >>> k
    array([[  10,    0, 4863, 1464]])
    >>> k[0][0] = 1e-3
    >>> k
    array([[   0,    0, 4863, 1464]])
    

    or

    >>> k
    array([[  0,    0, 4863, 1464]])
    >>> k[0][0] = 10.2
    >>> k
    array([[  10,    0, 4863, 1464]])
    

    but:

    >>> f = k.astype(float)
    >>> f
    array([[    0.,     0.,  4863.,  1464.]])
    >>> f[0][0] = 1e-3
    >>> f
    array([[  1.00000000e-03,   0.00000000e+00,   4.86300000e+03,
              1.46400000e+03]])
    

    Notice the . after the zeros.

    I would probably use

    >>> k = numpy.zeros((1,4))
    >>> k
    array([[ 0.,  0.,  0.,  0.]])
    

    instead; it defaults to float dtype.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple function which takes an array of characters as an argument,
I have a simple function, which I shall call myFunction . It takes two
I have a simple function that takes a char and return a string, in
I have a simple function that returns an NSString after decoding it. I use
I have a native library which is invoked by the JNI function called from
I have a simple function called a lot. Inside this function, I have many
I have a simple js function: function changeContent(id, content) { $(id).html(content); } which gets
I have a simple jQuery function that resizes text areas, and I want it
I have a simple JS function that needs to get called when AJAX call
I have a very simple package, which I eventually want to release through PyPI,

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.