I
I
Igor2015-11-22 23:45:20
Python
Igor, 2015-11-22 23:45:20

How to write equations for array elements?

I have an array dp:

def d_phi(a, b):
            return a
      dphi = quad(d_phi, t, t + 0.01, args=(x[0:2]))
      
      p     = np.zeros((1,4)) # Лучше объявить до начала работы функции
      dp    = np.zeros((1,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

But when I run it, I get an error:
IndexError: index 1 is out of bounds for axis 0 with size 1
What did I do wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2015-11-23
@ElMigele

It is obvious from the error that the problem is in the indexes (in the array declaration)
What does this line do?
dp = np.zeros((1,4))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question