Python Forum

Full Version: for loop and if translate from R in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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_
: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)
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.