How to convert the following IDL program lines to equivalent Python program lines?
Madhavan Bomidi
blmadhavan at gmail.com
Thu Nov 28 06:51:38 EST 2019
Hi,
I have the following IDL program lines. I want to write equivalent Python program lines. Can anyone suggest me equivalent Pythons program lines?
# ------------------- 1 ----------------------- #
How to handle the format in IDL to Python?
IDL program line:
print,'Column ',J,' of product matrix A*AINV:',format='(1X,A7,I3,A27)'
Python program line written by me:
print('Column '+str(j)+' of product matrix A*AINV:')
#-------------------2 ------------------------ #
How the JMP can be transformed in Python?
IDL program lines:
FOR K=1,M DO BEGIN
FOR I=1,M DO BEGIN
IF I NE K THEN BEGIN
IF WK(K-1,K-1) EQ 0 THEN BEGIN
L=1
JMP: IF WK(L-1,K-1) EQ 0 THEN BEGIN
L=L+1
GOTO, JMP
ENDIF
FOR J=K,2*M DO BEGIN
WK(K-1,J-1)=WK(K-1,J-1)+WK(L-1,J-1)
ENDFOR
ENDIF
U=-WK(I-1,K-1)/WK(K-1,K-1)
FOR J=K+1,2*M DO BEGIN
WK(I-1,J-1)=WK(I-1,J-1)+U*WK(K-1,J-1)
ENDFOR
ENDIF
ENDFOR
ENDFOR
JMP: RETURN
Python program lines:
for k in np.arange(1,M+1,dtype=int):
for i in np.arange(1,M+1,dtype=int):
if (i != k):
if (WK[k-1,k-1] == 0):
L = 1
if (WK[k-1,L-1] == 0): # JMP
L = L+1
for j in np.arange(k,2*M+1,dtype=int):
WK[j-1,k-1] = WK[j-1,k-1] + WK[j-1,L-1]
U = -WK[k-1,i-1]/WK[k-1,k-1]
for j in np.arange(k+1,2*M+1,dtype=int):
WK[j-1,i-1] = WK[j-1,i-1]+U*WK[j-1,k-1]
Can someone provide their feedback on whether I have done the correct transformation of the above IDL program lines to python program lines?
Look forward to the suggestions.
More information about the Python-list
mailing list