title: What is the fastest way to find the min and max value of a large multidimensional numpy array?
body: <p>I have a numpy array consisting of 20,000 RGB images of 220x220 pixels each. The array, <code>X_data</code>, therefore has the shape <code>(20000, 220, 220, 3)</code>.</p>
  <p>I'm looking for the fastest way to find the minimum and maximum pixel values across the entire dataset. I appreciate this type of task will take time because I'm searching through approximately 3 billion pixel values, but I'm hoping to improve on the solutions I have found already; which are the following:</p>
  <h3>Option 1: Flatten the array</h3>
  <p>Use <code>np.flatten</code> and then <code>np.min</code> and <code>np.max</code> on the resulting array:</p>
  <pre><code>flat = X_data.flatten()
  np.min(flat)
  np.max(flat)
  </code></pre>
  <p>This method took a total of 13min 11s (wall time) to find the min and max values.</p>
  <h3>Option 2: List comprehension</h3>
  <p>Use <code>np.amin</code> and <code>np.amax</code> to find the min and max for each image, append them to a list, and then find the min and max of that list:</p>
  <pre><code>min_val = np.min([np.amin(X_data[i]) for i in np.arange(X_data.shape[0])])
  max_val = np.max([np.amax(X_data[i]) for i in np.arange(X_data.shape[0])])
  </code></pre>
  <p>This method took a total of 8 minutes (wall time).</p>
  <p>Are there any faster methods for completing this task?</p>
  <h3>EDIT:</h3>
  <p>I forgot to mention in the original formulation of the question that I would like this to work on image datasets that have not been rescaled, ie those that contain images of varying sizes. This means that using <code>np.min</code> and <code>np.max</code> will not work, even though it is faster that the above options.</p>
  <p>Many thanks!</p>