title: Change shape of multi-dimensional NumPy array without changing dimensions
body: <p>I am currently monkey-patching a Scikit-Learn function and one of the lines requires a NumPy array with 2 dimensions. However, the data I am working with is a NumPy array with 3 dimensions, which raises the error "too many values to unpack."</p>
  
  <p>I am calling the K-Means function <code>fit</code> to cluster the data. My problem boils down to this following line of code, assuming <code>X</code> is the <code>ndarray</code> that I pass in:</p>
  
  <pre><code>n_samples, n_features = X.shape
  </code></pre>
  
  <p><code>X</code> is an array with 3 dimensions, like the following:</p>
  
  <pre><code>X = np.array([[[1, 2, 3],
                 [4, 5, 6]],
  
                [[7, 8, 9],
                 [10, 11, 12]],
  
                [[13, 14, 15],
                 [16, 17, 18]]])
  </code></pre>
  
  <p>The data represents a group of time series of data points that have 6 dimensions. For example, the first element, <code>[[1, 2, 3], [4, 5, 6]]</code> would represent a time series with samples from 2 time periods, each sample with 3 dimensions.</p>
  
  <p>And I have monkey-patched the <code>k_means_</code> code to allow me to perform clustering on an <code>ndarray</code> of <code>ndarray</code>s. My goal is to perform k-means on 2D arrays.</p>
  
  <p>Is it possible to set the shape of the 3D ndarray to 2 elements? For example, I tried converting the 3D array to a 2D array of objects but it ends up getting converted back to a 3D array.</p>
  
  <pre><code>np.array([[x.astype(object) for x in c] for c in combined])
  </code></pre>
  
  <p>Likewise, the following code is also converted back to a 3D array.</p>
  
  <pre><code>np.array([[np.array(x) for x in c] for c in combined])
  </code></pre>
  
  <p>The list comprehension <code>[[x.astype(object) for x in c] for c in combined]</code> looks like it creates the correct array, but because it is of type list, it no longer works in the function.</p>
  
  <p>I am looking for some way to "convert" a 3D NumPy array into 2 dimensions. Any help would be greatly appreciated!</p>
  
  <p>Note: I am not looking for a way to reshape the array. I need to keep all the dimensions but change the shape to ignore one of the dimensions.</p>