# What is the Julia equivalent of np.fromfunction?

**URL:** <https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-np-fromfunction/37908>\
**Category:** New to Julia\
**Tags:** question, array\
**Created:** [April 20, 2020, 4:21pm UTC](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-np-fromfunction/37908 "2020-04-20T16:21:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhezab](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rhezab](https://discourse.julialang.org/u/rhezab)\
**Post date:** [April 20, 2020, 4:21pm UTC](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-np-fromfunction/37908/1 "2020-04-20T16:21:28Z")

</div>

[Link to np.fromfunction documentation](https://numpy.org/doc/stable/reference/generated/numpy.fromfunction.html?highlight=fromfunction#numpy.fromfunction)

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

---

<div class="post-metadata">

**Author:** ![L\_Adam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/l_adam/32/12086_2.png) [@L\_Adam](https://discourse.julialang.org/u/L_Adam)\
**Post date:** [April 20, 2020, 4:29pm UTC](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-np-fromfunction/37908/2 "2020-04-20T16:29:07Z")

</div>

maybe this?

```julia
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]

```

---

<div class="post-metadata">

**Author:** ![rhezab](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rhezab](https://discourse.julialang.org/u/rhezab)\
**Post date:** [April 20, 2020, 4:37pm UTC](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-np-fromfunction/37908/3 "2020-04-20T16:37:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![L\_Adam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/l_adam/32/12086_2.png) [@L\_Adam](https://discourse.julialang.org/u/L_Adam)\
**Post date:** [April 20, 2020, 4:39pm UTC](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-np-fromfunction/37908/4 "2020-04-20T16:39:03Z")

</div>

for comprehension is always faster

---

<div class="post-metadata">

**Author:** ![rhezab](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rhezab](https://discourse.julialang.org/u/rhezab)\
**Post date:** [April 20, 2020, 4:44pm UTC](https://discourse.julialang.org/t/what-is-the-julia-equivalent-of-np-fromfunction/37908/5 "2020-04-20T16:44:08Z")

</div>

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

Thank you!
