# Vectorization of ForwardDiff.gradient function

**URL:** https://discourse.julialang.org/t/vectorization-of-forwarddiff-gradient-function/6736
**Category:** New to Julia
**Created:** [October 28, 2017, 5:30am UTC](https://discourse.julialang.org/t/vectorization-of-forwarddiff-gradient-function/6736 "2017-10-28T05:30:30Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [October 28, 2017, 8:10pm UTC](https://discourse.julialang.org/t/vectorization-of-forwarddiff-gradient-function/6736/4 "2017-10-28T20:10:47Z")

</div>

> First, suppose I apply the vectorized funciton, but on a single point

Basically, just don’t do this. `f.(r1)` _syntactically means_ "apply f elementwise to `r1`. If `r1` is a vector, then you’re asking Julia to apply `f` to each element of the vector, which isn’t what you actually want. So use `f(r1)` when you have one element or `f.(rvals)` when you have a vector of elements.

> How do I convert between the data types?

You can just construct it directly as `[x, y]`, or if you already have the N array of points, you can do `[r[:, i] for i in 1:size(r, 2)]`, for example.

---

_[View the full topic](https://discourse.julialang.org/t/vectorization-of-forwarddiff-gradient-function/6736)._
