0
        from sympy.physics.hydrogen import R_nl
        from sympy import var
        from sympy import Matrix
        import sympy as sp
        sp.init_printing(use_latex="mathjax")
        r1,Z=var("r1 Z")
        r2,Z=var("r2,Z")
        O=sp.zeros(3)
        k=0
        for i in range(1,3,1):
          for j in range(0,i,1):

             print("n=",i,"l=",j, ":")
             O[k]= R_nl(i,j,r1,Z)
             display(O[k])
             print("------------------------------------")
             k=k+1

In the above code I have stored the in built functions R_nl (it is radial part of hydrogen atom wave functions) in an one dimensional array. I want that to be stored in two dimensional array. The in built R_nl functions has to positive integer parameters n and l, so it would be nice if I could store it in two dimensional array. Can someone help me in storing this in two dimensional array ?? If I try to store this in two dimensional array, it throws the following error message


 TypeError Traceback (most recent call last)
<ipython-input-22-6bcaaf0f91e4> in <module>
      19 
      20         print("n=",i,"l=",j, ":")
 ---> 21         O[k][s]= R_nl(i,j,r1,Z)
      22         display(O[k][s])
      23         print("------------------------------------")

      TypeError: 'Zero' object does not support item assignment
user135580
  • 105
  • 1
  • 7

1 Answers1

1

Try to access the Matrix like O[k, s] instead of O[k][s].

smichr
  • 16,948
  • 2
  • 27
  • 34
  • However how do I define multidimensional sympy array? Is it possible this to extend this to multidimensional array in sympy as I am getting error message once I go beyond 2 dimensions as you have said. How do I define multidimensional arrays in sympy Can someone explain ? – user135580 Dec 01 '18 at 20:12
  • Could you store it in a python dict with the key being the 3 indices stored as a tuple: `R_nl[(1,2,1)] = 3` – smichr Dec 10 '18 at 04:28
  • I finally found a way out to store and to use multidimensional arrays dynamically . I have to use mutable n dimensional array class to store as many functions as I want. – user135580 Dec 10 '18 at 17:51