# Sum of array as an others array value

**URL:** <https://discourse.julialang.org/t/sum-of-array-as-an-others-array-value/10827>\
**Category:** General Usage\
**Created:** [May 10, 2018, 9:49pm UTC](https://discourse.julialang.org/t/sum-of-array-as-an-others-array-value/10827 "2018-05-10T21:49:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![St0n](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/st0n/32/4126_2.png) [@St0n](https://discourse.julialang.org/u/St0n)\
**Post date:** [May 10, 2018, 9:49pm UTC](https://discourse.julialang.org/t/sum-of-array-as-an-others-array-value/10827/1 "2018-05-10T21:49:57Z")

</div>

Hi everyone, im new and this is my first question here.  
I’m wondering why this is not possible:

If i Type:

```julia
A=[1.0, 2.0, 3.0, 4.0, 5.0];
B=zeros(5);

```

and then

```julia
sum(A)=B[1]

```

i get the error Message:

```julia
error in method definition: function Base.sum must be explicitly imported to be extended

```

Why is this ?

Typing

```julia
typeof(sum(A))

```

its Float64 like the elements of B?

also

```julia
sum(A[1:3])=B[1]

```

does not work , but now with the error mesasage:

```julia
syntax: "A[1:3]" is not a valid function argument name

```

Thanks

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [May 10, 2018, 9:53pm UTC](https://discourse.julialang.org/t/sum-of-array-as-an-others-array-value/10827/2 "2018-05-10T21:53:01Z")

</div>

You can’t extend a `Base` method without importing it first. `sum(A) = B[1]` is a method definition, this is entirely different from just typing `sum(A)`, because `=` is an assignment operator.

`sum(A[1:3])=B[1]` is invalid syntax.

---

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [May 10, 2018, 10:05pm UTC](https://discourse.julialang.org/t/sum-of-array-as-an-others-array-value/10827/3 "2018-05-10T22:05:00Z")

</div>

Welcome!

Perhaps it would be useful if you explain what you’re trying to do, or what you expect to happen?

Also, to show code please use backticks (`) or triple-backticks(```) (I took the liberty of editing your post).

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [May 10, 2018, 11:59pm UTC](https://discourse.julialang.org/t/sum-of-array-as-an-others-array-value/10827/4 "2018-05-10T23:59:46Z")

</div>

It is not clear from your question what you really want to do or what is the expected behavior that you assumed. Perhaps you mean to do this?

```julia
A = [1.0, 2.0, 3.0, 4.0, 5.0]
B = zeros(5)

B[1] = sum(A)
B[1] = sum(A[1:3]) 

```

---

<div class="post-metadata">

**Author:** ![St0n](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/st0n/32/4126_2.png) [@St0n](https://discourse.julialang.org/u/St0n)\
**Post date:** [May 11, 2018, 8:34am UTC](https://discourse.julialang.org/t/sum-of-array-as-an-others-array-value/10827/5 "2018-05-11T08:34:45Z")

</div>

Seif\_Shebl, you are right, that is what i really wanted t do…and it works fine.  
what a stupid mistake of mine…  
Thanks a lot for the answers to everybody.
