I have written an R function that takes a vector as input and returns as output another vector so that the minimum of the input vector is replaced by 1, the element that is greater than the minimum is replaced by 2 etc until the maximum of the vector, which is replaced by the length of the vector. This is my function:
resc<-function(x){
m<-length(unique(x))
nor<-rep(0,length(x))
x_2<-x
for(i in 1:m){
temp<-min(x_2)
temp_2<-which(x==temp)
nor[temp_2]<-i
x_2<-x_2[-which(x_2==temp)]
}
return(nor)
}
How can I rewrite this function in Python? I tried, but I was a bit confused with the use of command 'which'.