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]
-
Can you add some of the code which you have tried? This way we can have a look and find your problem together.Stijn Van Daele– Stijn Van Daele2017-03-25 15:44:19 +00:00Commented 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)Akashdeep Gill– Akashdeep Gill2017-03-25 15:51:17 +00:00Commented 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 sumAkashdeep Gill– Akashdeep Gill2017-03-25 15:53:19 +00:00Commented Mar 25, 2017 at 15:53
Add a comment
|
1 Answer
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)
3 Comments
Akashdeep Gill
And can u tell me this also
Akashdeep Gill
i just wanted to know the stuff i edited above can u help me on that also
Stijn Van Daele
I do not understand the question anymore. Please stop changing the original question.