Trying to pass more than 2 vectors to a function in R

前端 未结 2 887
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-26 10:50

I want to compute e^(ax+b) over a=-1:1 and b=-1:1 for various values of X. I want the output in the form a list of 5 elements. Each elemen

2条回答
  •  清酒与你
    2021-01-26 11:47

    In this case, you should only vectorize the variable x.

    sigm1 = Vectorize(function(a=-1:1,b=-1:1,x){
                        outer(a,b,sigm,x)}, vectorize.args = "x" ,SIMPLIFY = FALSE)
    

    Then running sigm1(-1:1,-1:1,1:3) will gives the result you want.

提交回复
热议问题