Python Forum
for loop and if translate from R in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: for loop and if translate from R in Python (/thread-8109.html)



for loop and if translate from R in Python - Joey21 - Feb-06-2018

Hi everyone,

i have a new work in data science.
My problem is that i always code in R and in python i have no good experience

1)
my code in R
Quote: for(i in 1:length(l)) X[,i] = MF[[i]](x)

in Python
Quote:for i in range(1,1+l.length()):
X[:,i]= MF[i](x)

i really don't know if it is right Dodgy

2)
code in R
Quote:if(is.na(sv[1])) l = rep(0,length(V)) else l = sv[-1]

Python
this is very confusing for me i have noooo ideas Sad


RE: for loop and if translate from R in Python - wavic - Feb-06-2018

It looks simple code but I have not idea what the R code is doing. My eyes hurt looking at it. Big Grin
Can you explain it or write a pseudo code_


RE: for loop and if translate from R in Python - Joey21 - Feb-06-2018

:D lol

ok
i will try:
1)
i think the for loop is right until X[,i]=MF[[i]](x)
and that means from the matrix X i column = ...
I give you a example for MF[[]] -> e=[[1,2,3],[4,5,6]]
And e[[2]] =4
My english is not so good (sorry)


RE: for loop and if translate from R in Python - sparkz_alot - Feb-06-2018

I've never used R either, but it seems you could use a known set of values, plug them into your R program and record the result. Then plug the same values into your Python code and see if you get the same result.