# Map(my\_fun, Array Array) What wrong?

**URL:** <https://discourse.julialang.org/t/map-my-fun-array-array-what-wrong/47183>\
**Category:** General Usage\
**Created:** [September 24, 2020, 6:43am UTC](https://discourse.julialang.org/t/map-my-fun-array-array-what-wrong/47183 "2020-09-24T06:43:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [September 24, 2020, 6:43am UTC](https://discourse.julialang.org/t/map-my-fun-array-array-what-wrong/47183/1 "2020-09-24T06:43:09Z")

</div>

```julia
using StringDistances
function CLD(a,b)
result=fill(0.0,size(b,1))
for p=1:size(a,1)
result[p]=compare(a[p,:][],b[p,:][],DamerauLevenshtein())
end
return result
end
A=rand(5,3);
B=rand(5,3)
julia> CLD(A[1,:],B[1,:])
3-element Array{Float64,1}:
 0.0
 0.0
 0.0

```

All is OK , but:

```julia
julia> map(+,A[1,:],B[1,:])
3-element Array{Float64,1}:
 1.5078756063214551
 0.9446955888815904
 1.5179640101430865

julia> map(CLD,A[1,:],B[1,:])
ERROR: MethodError: no method matching getindex(::Float64, ::Int64, ::Colon)
Closest candidates are:
  getindex(::Number, ::Integer) at number.jl:76
  getindex(::Number, ::Integer...) at number.jl:81
  getindex(::Number) at number.jl:75

```

What wrong ?  
Paul

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 24, 2020, 6:54am UTC](https://discourse.julialang.org/t/map-my-fun-array-array-what-wrong/47183/2 "2020-09-24T06:54:13Z")

</div>

```julia
julia> a = 3
3

julia> a[1,:]
ERROR: MethodError: no method matching getindex(::Int64, ::Int64, ::Colon)

```

When you use `map` you apply `CLD` to each element in `A[1, :]` and `B[1, :]`, which are scalars. And you cannot call a slicing operation on scalars.

Why are you using `map` instead of just `CLD(A[1,:],B[1,:])`?

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 24, 2020, 7:00am UTC](https://discourse.julialang.org/t/map-my-fun-array-array-what-wrong/47183/3 "2020-09-24T07:00:26Z")

</div>

> [@programista](#):
>
> `a[p,:][]`

What’s up with this indexing, by the way? Don’t you mean

```julia
a[p,:]

```

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [September 24, 2020, 9:10am UTC](https://discourse.julialang.org/t/map-my-fun-array-array-what-wrong/47183/4 "2020-09-24T09:10:58Z")

</div>

In one move I wanted to do a CLD for all the matrix lines, similar to:

```julia
julia> map(+,A,B)
5×3 Array{Float64,2}:
 1.50788 0.944696 1.51796
 1.41019 1.62973 1.79299
 1.17479 1.75749 1.18765
 1.73444 1.37048 0.866828
 0.810632 0.398073 0.73858

```

Paul

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 24, 2020, 9:15am UTC](https://discourse.julialang.org/t/map-my-fun-array-array-what-wrong/47183/5 "2020-09-24T09:15:41Z")

</div>

But you’re only sending in the first row. You’ll have to give `map` a collection of all the rows.

Maybe something like this (untested)

```julia
map(CLD, eachrow(A), eachrow(B))

```

BTW, you should work column-by-column, since Julia Arrays are column-major.
