<p dir="auto">I came about this when using the <code class="notranslate">sum</code> function and <code class="notranslate">DataFrames()</code>. Consider the following short example.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Df = DataFrame()
M = reshape(rand(1:20, 16), (4, 4))
Msum = sum(M, 2)
Df[:c1] = Msum

Main&gt; Df[:c1] = Msum
ERROR: ArgumentError: setindex!(::DataFrame, ...) only broadcasts scalars, not arrays
Stacktrace:
 [1] setindex!(::DataFrames.DataFrame, ::Array{Int64,2}, ::Symbol) at /Users/abmlab/.julia/v0.6/DataFrames/src/dataframe/dataframe.jl:372
 [2] eval(::Module, ::Any) at ./boot.jl:235"><pre class="notranslate"><code class="notranslate">Df = DataFrame()
M = reshape(rand(1:20, 16), (4, 4))
Msum = sum(M, 2)
Df[:c1] = Msum

Main&gt; Df[:c1] = Msum
ERROR: ArgumentError: setindex!(::DataFrame, ...) only broadcasts scalars, not arrays
Stacktrace:
 [1] setindex!(::DataFrames.DataFrame, ::Array{Int64,2}, ::Symbol) at /Users/abmlab/.julia/v0.6/DataFrames/src/dataframe/dataframe.jl:372
 [2] eval(::Module, ::Any) at ./boot.jl:235
</code></pre></div>
<p dir="auto">but if I do this</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tarr = zeros(Int64, 4)
Df[:c1] = tarr"><pre class="notranslate"><code class="notranslate">tarr = zeros(Int64, 4)
Df[:c1] = tarr
</code></pre></div>
<p dir="auto">It works. Both are one dimensional arrays with 4 elements, so what gives? I think its a problem with dimensions. See following</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Main&gt; Msum = sum(M, 2)
4×1 Array{Int64,2}:
 29
 29
 35
 41"><pre class="notranslate"><code class="notranslate">Main&gt; Msum = sum(M, 2)
4×1 Array{Int64,2}:
 29
 29
 35
 41
</code></pre></div>
<p dir="auto">so the <code class="notranslate">sum</code> function produces a one dimensional array but the type is set to <code class="notranslate">Array{Int64, 2}</code>. This is further seen by</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Main&gt; size(Msum)
(4, 1)

Main&gt; size(tarr)
(4,)"><pre class="notranslate"><code class="notranslate">Main&gt; size(Msum)
(4, 1)

Main&gt; size(tarr)
(4,)
</code></pre></div>
<p dir="auto">Is this a bug or is this expected behaviour. How can I change the dimension from the <code class="notranslate">sum</code> function to 1? The <code class="notranslate">reshape</code> function dosn't work.</p>
<p dir="auto">edit: <code class="notranslate">reshape</code> does work by running <code class="notranslate">reshape(Msum, (15, ))</code></p>
<p dir="auto">Following this discussion on julia-users: <a href="https://groups.google.com/forum/#!topic/julia-users/V-meqUZtb7k" rel="nofollow">https://groups.google.com/forum/#!topic/julia-users/V-meqUZtb7k</a></p>
<p dir="auto">I find the fact that <code class="notranslate">sum(A,1)</code> and <code class="notranslate">A[1,:]</code> have different shapes in 0.5 counter intuitive.  I am not aware of other languages for which the equivalent expressions have different shapes.  It leads to unexpected results when computing e.g. <code class="notranslate">A[1,:] ./ sum(A,1)</code>.  At least in the case of <code class="notranslate">sum</code>, it seems like <code class="notranslate">sum(A,1)</code> should be equivalent to <code class="notranslate">A[1,:] + A[2,:] + A[3,:] + ...</code></p>
<p dir="auto">However, as <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/timholy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/timholy">@timholy</a> pointed out, this behavior can be useful for broadcasting with expressions like <code class="notranslate">A ./ sum(A,1)</code>.</p>
<p dir="auto">For me, having the default slicing and array reduction behavior be consistent seems the natural choice, meaning that <code class="notranslate">sum(A,1)</code> should drop the first dimension.  But I understand the attractiveness of not dropping dimensions for broadcasting.  What are others' thoughts?</p>