Hey julians. I found this one a little tricky to fix. I have a rosenbrock function

Hey julians. I found this one a little tricky to fix. I have a rosenbrock function that takes 2 values and returns 1 value. So I was trying to run this as a comprehension, but I am getting out a (401,401) array, instead of a (401,1) array. Here is the code.

x = -2:0.01:2
y = -2:0.01:2
rosenbrock(x,p) =  (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
z = [rosenbrock([i, j], p) for i=x, j=y]

But I keep getting out a (401,401) array instead of a 401,1 array. Now it makes sense that the comprehension is iterating over the i and j dimensions, so there are probably repeated entries. But still I was not clear on how to fix this. I tried parenthesis (i=x, j=y).

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

Is it what you want ?

z = [rosenbrock([ij...], p) for ij ∈ zip(x,y)]
1 Like