I
I
Igor2015-11-26 23:02:34
Python
Igor, 2015-11-26 23:02:34

How to change vector values?

Declared a variable and set values ​​for it:

dphi = x[0:2] * 0.1
      
p     = np.zeros((4)) 
dp    = np.zeros((4))
      
dp[0] = (-dphi[0] * p[1] - dphi[1] * p[2] - dphi[2] * p[3])/2
dp[1] = ( dphi[0] * p[0] + dphi[2] * p[2] - dphi[1] * p[3])/2
dp[2] = ( dphi[1] * p[0] - dphi[2] * p[1] + dphi[0] * p[3])/2
dp[3] = ( dphi[2] * p[0] + dphi[1] * p[1] - dphi[0] * p[1])/2

p = p + dp

When run, the program gives an error:
dp[0] = (-dphi[0] * p[1] - dphi[1] * p[2] - dphi[2] * p[3])/2
IndexError: index 2 is out of bounds for axis 0 with size 2
What is wrong and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Druzhaev, 2015-11-27
@borodaturan

You are trying to use the 3rd element of the dphi array in the expression dphi[2] * p[3]. And they created an array with only 2 elements: dphi = x[0:2] * 0.1.
Apparently it is necessary to do so: dphi = x[: 3] * 0.1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question