# Promoting a broadcasted array

**URL:** https://discourse.julialang.org/t/promoting-a-broadcasted-array/117498
**Category:** General Usage
**Tags:** convert
**Created:** [July 26, 2024, 2:23am UTC](https://discourse.julialang.org/t/promoting-a-broadcasted-array/117498 "2024-07-26T02:23:16Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [July 26, 2024, 11:36am UTC](https://discourse.julialang.org/t/promoting-a-broadcasted-array/117498/6 "2024-07-26T11:36:03Z")

</div>

> [@cstjean](#):
>
> Alternatively, is there an efficient Base function that promotes all values in an Array to a concrete type? `promote_to_same_type(Any[1,2,9.4])` that yields `[1.0,2.0,9.4]`?

Linking [related old post](https://discourse.julialang.org/t/type-intersection-in-arrays/12035/31).

FWIW, the following `promote_array()` function, inspired by the code above, seems to run a bit faster:

```julia
promote_array(v) = convert(Array{eltype(promote(map(zero, unique(typeof(v) for v in v))...))}, v)

v = rand((1, 4.5), 100_000)
promote_array(v)
@btime promote_array($v) # 3.6 ms (99526 allocs: 2.28 MiB)

```

---

_[View the full topic](https://discourse.julialang.org/t/promoting-a-broadcasted-array/117498)._
