# How to create a list/vector/matrix of specified size, each value filled with -Inf or Inf?

**URL:** <https://discourse.julialang.org/t/how-to-create-a-list-vector-matrix-of-specified-size-each-value-filled-with-inf-or-inf/98040>\
**Category:** New to Julia\
**Tags:** question, data\_structures\
**Created:** [April 28, 2023, 1:00pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-vector-matrix-of-specified-size-each-value-filled-with-inf-or-inf/98040 "2023-04-28T13:00:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![meet.saiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/meet.saiya/32/49312_2.png) [@meet.saiya](https://discourse.julialang.org/u/meet.saiya)\
**Post date:** [April 28, 2023, 1:00pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-vector-matrix-of-specified-size-each-value-filled-with-inf-or-inf/98040/1 "2023-04-28T13:00:30Z")

</div>

Hi all,  
Is there a way to create a vector or list or matrix of specified size, all of them initialized to either of the infinity values? There are functions for zeros, ones and so on. I was wondering if there is one for Inf and if not how to create such a object?

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [April 28, 2023, 1:13pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-vector-matrix-of-specified-size-each-value-filled-with-inf-or-inf/98040/2 "2023-04-28T13:13:40Z")

</div>

For a vector or matrix you can use `fill`

```julia
julia> fill(-Inf, 5)
5-element Vector{Float64}:
 -Inf
 -Inf
 -Inf
 -Inf
 -Inf

julia> fill(Inf, (5, 2))
5×2 Matrix{Float64}:
 Inf Inf
 Inf Inf
 Inf Inf
 Inf Inf
 Inf Inf

```

---

<div class="post-metadata">

**Author:** ![meet.saiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/meet.saiya/32/49312_2.png) [@meet.saiya](https://discourse.julialang.org/u/meet.saiya)\
**Post date:** [April 28, 2023, 1:58pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-vector-matrix-of-specified-size-each-value-filled-with-inf-or-inf/98040/3 "2023-04-28T13:58:01Z")

</div>

> [@dmbates](#):
>
> `fill(-Inf, 5)`

Thanks! This works.
