What is the Julia equivalent of np.fromfunction?

Link to np.fromfunction documentation

I would like to fill an array with values as a function of its indices.

1 Like

maybe this?

map(f, Iterators.product(1:nrow, 1:ncol))
# or a simple for loop
[f(i, j) for i in 1:nrow, j in 1:ncol]
3 Likes

Thanks! map is what I’m looking for.

I assume using map is better? Do you know if they are the same under the hood?

for comprehension is always faster

1 Like

I just tried it out, you’re right! That’s interesting…

Thank you!