2

xs = np.linspace(-1,1,6)# [ -1 -0.6 -0.2 0.2 0.6 1] i want it to shift [ -0.6 -0.2 0 0 0.2 0.6]

3
  • Can you add some of the code which you have tried? This way we can have a look and find your problem together. Commented Mar 25, 2017 at 15:44
  • def chainLength(xs,ys): LL = np.sqrt((xs - (xs - 1)**2) + ((ys - (ys - 1))**2)) return np.sum(LL) Commented Mar 25, 2017 at 15:51
  • and this is notation of length of path math.sqrt(xj - x(j - 1))**2 + (yj - y(j - 1))**2 and i can't use loops onyl numpy to get the sum Commented Mar 25, 2017 at 15:53

1 Answer 1

1

Since the question is very vague, I am assuming that you're having a problem with the np.sqrt. Since this might create Nan values, you can exchange them for zeros. Hereby avoiding this problem.

For me, your code works.

import numpy as np

xs = np.array([ 2,  3,  1,  0, 10,  0, 10,  0, 10])
ys = np.array([ 2,  3,  1,  0, 10,  0, 10,  0, 10])

def chainLength(xs,ys): 


    LL = np.sqrt((xs - (xs - 1)**2) + ((ys - (ys - 1))**2)) 
    LL = np.nan_to_num(LL)
    return (np.sum(LL))

chainLength(xs, ys)
Sign up to request clarification or add additional context in comments.

3 Comments

And can u tell me this also
i just wanted to know the stuff i edited above can u help me on that also
I do not understand the question anymore. Please stop changing the original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.