title: How should I convert a singleton Array to a scalar?
body: <p>Let's say I have an <code>Array</code> variable called <code>p</code>:</p>
  
  <pre><code>julia&gt; p = [5]
  julia&gt; typeof(p)
  Array{Int64,1}
  </code></pre>
  
  <p>How should I convert it to scalar? <code>p</code> may also be 2-dimensional:</p>
  
  <pre><code>julia&gt; p = [1]'' 
  julia&gt; typeof(p)
  Array{Int64,2}
  </code></pre>
  
  <p>(Note: the double transpose trick to increase dimentionality <a href="https://github.com/JuliaLang/julia/issues/4774" rel="noreferrer">might not work in future versions of Julia</a>)</p>
  
  <p>Through appropriate manipulation, I can make <code>p</code> of any dimension, but how should I reduce it to a scalar?</p>
  
  <hr>
  
  <p>One viable approach is <code>p=p[1]</code>, but that will not throw any error if <code>p</code> has more than one element in <code>p</code>; so, that's no good to me. 
  I could build my own function (with checking), </p>
  
  <pre><code>function scalar(x)
      assert(length(x) == 1)
      x[1]
  end
  </code></pre>
  
  <p>but it seems like it must be reinventing the wheel.</p>
  
  <p>What does not work is <code>squeeze</code>, which simply peels off dimensions until <code>p</code> is a zero-dimensional array.</p>
  
  <p>(Related to <a href="https://stackoverflow.com/questions/28845323/julia-convert-1x1-array-to-number/28845582#28845582">Julia: convert 1x1 array from inner product to number</a> but, in this case, operation-agnostic.)</p>