# Summation of rows of array without allocation

**URL:** <https://discourse.julialang.org/t/summation-of-rows-of-array-without-allocation/43313>\
**Category:** General Usage\
**Created:** [July 18, 2020, 10:52pm UTC](https://discourse.julialang.org/t/summation-of-rows-of-array-without-allocation/43313 "2020-07-18T22:52:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaraujo71](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaraujo71/32/10635_2.png) [@aaraujo71](https://discourse.julialang.org/u/aaraujo71)\
**Post date:** [July 18, 2020, 10:52pm UTC](https://discourse.julialang.org/t/summation-of-rows-of-array-without-allocation/43313/1 "2020-07-18T22:52:25Z")

</div>

Suppose we have an array **x** with _m_ rows and _n_ columns and a vector s with _m_ elements. I would like to sum the elements of each row of array **x** and save these results in vector **s**.

This can be easily implemented in Julia using `v = sum(x, dims = 2)`. However, this procedure allocates extra memory for the operation. Is it any way to do this operation without extra allocation (and not using cycles)? I was trying function `sum!`, but it does not accept keyword argument `dims`.

---

<div class="post-metadata">

**Author:** ![aaraujo71](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaraujo71/32/10635_2.png) [@aaraujo71](https://discourse.julialang.org/u/aaraujo71)\
**Post date:** [July 18, 2020, 11:42pm UTC](https://discourse.julialang.org/t/summation-of-rows-of-array-without-allocation/43313/2 "2020-07-18T23:42:14Z")

</div>

I found the solution: `sum!(v, x)`
