# Lambdify function to matrix

**URL:** <https://discourse.julialang.org/t/lambdify-function-to-matrix/123163>\
**Category:** General Usage\
**Tags:** question, sympy\
**Created:** [November 27, 2024, 1:05pm UTC](https://discourse.julialang.org/t/lambdify-function-to-matrix/123163 "2024-11-27T13:05:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [November 27, 2024, 1:05pm UTC](https://discourse.julialang.org/t/lambdify-function-to-matrix/123163/1 "2024-11-27T13:05:02Z")

</div>

Hi there! Im trying to obtain a 20x20 matrix from the next code

```julia
fn = lambdify(t, [V, g, k])
ges = range(1, 2, 20); kes = range(1, 2, 20)
fn.(1, ges, kes)

```

But I obtain a vector…

> 20-element Vector{ComplexF64}:

Function “t” is a long expression obtained from solving linear system with SymPy Package.

Any ideas how can I handle this?  
Thanks!

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [November 27, 2024, 2:26pm UTC](https://discourse.julialang.org/t/lambdify-function-to-matrix/123163/2 "2024-11-27T14:26:51Z")

</div>

I’m not familiar with SymPy, but in this case, I’m guessing that you need to transpose one of your arrays, either `ges` or `kes`. Here’s an example with a made-up `fn`:

```julia
fn(x, y, z) = y*z + x 

ges = 1:5
kes = 1:5

fn.(1, ges, kes)

```

`ges` and `kes` are both vectors, so broadcasting will produce a vector:

```julia
5-element Vector{Int64}:
  2
  5
 10
 17
 26

```

However, running

```julia
fn.(1, ges, kes')

```

will produce a matrix:

```julia
5×5 Matrix{Int64}:
 2 3 4 5 6
 3 5 7 9 11
 4 7 10 13 16
 5 9 13 17 21
 6 11 16 21 26

```

and running

```julia
fn.(1, ges', kes)

```

will produce the same matrix transposed.

See the Julia manual here for details: [Single- and multi-dimensional Arrays · The Julia Language: Broadcasting](https://docs.julialang.org/en/v1/manual/arrays/#Broadcasting)

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [November 27, 2024, 5:57pm UTC](https://discourse.julialang.org/t/lambdify-function-to-matrix/123163/3 "2024-11-27T17:57:18Z")

</div>

You are absolutely right!  
Thanks!
