title: How to reshape Arrays quickly
body: <p>In the following code I am using the Julia Optim package for finding an optimal matrix with respect to an objective function.
  Unfortunately the provided optimize function only supports vectors, so I have to transform the matrix to a vector before passing it to the optimize function, and also transform it back when using it in the objective function.</p>
  
  <pre><code>function opt(A0,X)    
      I1(A) = sum(maximum(X*A,1))
  
      function transform(A)
        # reshape matrix to vector
        return reshape(A,prod(size(A)))
      end
  
      function transformback(tA)
        # reshape vector to matrix
        return reshape(tA, size(A0))
      end
  
      obj(tA) = -I1(transformback(tA))
      result = optimize(obj, transform(A0), method = :nelder_mead)
      return transformback(result.minimum)
  end
  </code></pre>
  
  <p>I think Julia is allocating new space for this every time and it feels slow, so what would be a more efficient way to tackle this problem?</p>