Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello Volker,



I do not know, why you want to encode the index j in the name,
but you could use 'exec()' for this:

import numpy as np
N = 4
A = 3
for j in srange(N):
   exec('L'+str(j)+"=np.empty(A)")

Then L1 to L4 gets defined:

>>> L1
array([  9.79748720e-251,   2.90930926e-252,   2.34745402e-251])

Hello Volker,mresimulator,



I do not know, why you want to encode the index j in the name,
but you could use 'exec()' for this:

import numpy as np
N = 4
A = 3
for j in srange(N):
   exec('L'+str(j)+"=np.empty(A)")

Then L1 to L4 gets defined:

>>> L1
array([  9.79748720e-251,   2.90930926e-252,   2.34745402e-251])