Indexerror: index 3 is out of Bounds for Axis 0 with size 2

Asked

Viewed 413 times

0

D[i][j+1] = - u_med[i+1]/(delta_r[i]*delta_r[i+1])

Indexerror: index 3 is out of Bounds for Axis 0 with size 2

I’ve had another problem with that code and I asked here, but the problem now is this.

I’m working with the one-dimensional Schrödinger equation on a variable grid... So I’m trying to write it in matrix form, with a symmetric N x N matrix.

I tried using np.zeros because before I was giving another error because I was trying to access values in empty lists.

When I try to write np.zeros((n,n)), it gives the following error:

D[i][j+1] = - u_med[i+1]/(delta_r[i]*delta_r[i+1])

Valueerror: Setting an array element with a Sequence.

How can I reverse that?

n = 51
D = np.zeros((n,2))
for i in range(2,n):
  for j in range(2,n):
    if i == j:
      D[i][j+1] = - u_med[i+1]/(delta_r[i]*delta_r[i+1])
      t1 = u_med[i+1]/(delta_r[i]*delta_r[i])
      t2 = u_med[i]/(delta_r[i]*delta_r[i])
      D[i][j]= t1 + t2 + V[i]
      D[i+1][j]= - u_med[i+1]/(delta_r[i]*delta_r[i+1])
  • 1

    By error, you are accessing index 3 of a sequence that only has 2 elements.

  • Hello, thank you for replying again. But as for the second case.. When I try to write np.zeros((n,n)), it gives the following error: D[i][j+1] = - u_med[i+1]/(delta_r[i]*delta_r[i+1]) Valueerror: Setting an array with a Sequence.

  • Boy, this error happens when you access index 3 of a sequence that only has 2 elements. Abs!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.