title: Getting the dtype of a result array in numpy
body: <p>I want to preallocate memory for the output of an array operation, and I need to know what dtype to make it.  Below I have a function that does what I want it to do, but is terribly ugly.</p>
  
  <pre><code>import numpy as np
  
  def array_operation(arr1, arr2):
      out_shape = arr1.shape
      # Get the dtype of the output, these lines are the ones I want to replace.
      index1 = ([0],) * arr1.ndim
      index2 = ([0],) * arr2.ndim
      tmp_arr = arr1[index1] * arr2[index2]
      out_dtype = tmp_arr.dtype
      # All so I can do the following.
      out_arr = np.empty(out_shape, out_dtype)
  </code></pre>
  
  <p>The above is pretty ugly.  Does numpy have a function that does this?</p>