# Range element wise product

**URL:** <https://discourse.julialang.org/t/range-element-wise-product/49966>\
**Category:** General Usage\
**Created:** [November 11, 2020, 5:10am UTC](https://discourse.julialang.org/t/range-element-wise-product/49966 "2020-11-11T05:10:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rojesh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rojesh/32/15390_2.png) [@Rojesh](https://discourse.julialang.org/u/Rojesh)\
**Post date:** [November 11, 2020, 5:10am UTC](https://discourse.julialang.org/t/range-element-wise-product/49966/1 "2020-11-11T05:10:45Z")

</div>

Trying to multiply a range with an array gave a no method matching error

```julia
1:4 .* [1,2,3,4]

```

ERROR: MethodError: no method matching (::Colon)(::Int64, ::Array{Int64,1})

Rather than accepting it as range it takes in as Int64 type. Why does it fail to work in this way ?

it seems to work with range in parenthesis

```julia
(1:4) .* [1,2,3,4]

```

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [November 11, 2020, 5:17am UTC](https://discourse.julialang.org/t/range-element-wise-product/49966/2 "2020-11-11T05:17:29Z")

</div>

This is because the code is being read as `1:(4 .* [1,2,3,4])`.

You can investigate this yourself by quoting and dumping the code:

```julia

julia> ex = :(1:4 .* [1,2,3,4])
:(1:4 .* [1, 2, 3, 4])

julia> dump(ex)
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol :
    2: Int64 1
    3: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol .*
        2: Int64 4
        3: Expr
          head: Symbol vect
          args: Array{Any}((4,))
            1: Int64 1
            2: Int64 2
            3: Int64 3
            4: Int64 4

```
