title: I/O buffer error in numpy
body: <p>I have a weight matrix (W) which is of size 400 x 8537. </p>
  
  <p>Each cell in <strong>W</strong> has some numeric value. </p>
  
  <p>Now I am trying to create another Y matrix of size 100 X8537 by the following analytical solution implemented in numpy. </p>
  
  <p>Here <strong>X is a 400 x 100</strong> numeric matrix and<br>
  <strong>P is a 300 x 8537</strong> matrix , therefore P[:,i]= 300X1 vector. </p>
  
  <pre><code>for i, Wi in enumerate(W.T):
              Y[:,i] = np.linalg.solve(np.dot(X.T, np.dot(np.diag(Wi), X)) + lambda_ * np.eye(n_factors),
                                   np.dot(X.T, np.dot(np.diag(Wi), P[:, i])))
              print('{}th row of Y is completed'.format(i))
  </code></pre>
  
  <p>The problem is that since <strong>W.T is 8537 x 400</strong>, the above step is iterating 8537 times and adding one column at a time to Y matrix. </p>
  
  <p>After some 1100+ iterations it throws the following error :</p>
  
  <pre><code>1109th row of Y is completed
  1110th row of Y is completed
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-68-d3bf04b641ea&gt; in &lt;module&gt;()
  ----&gt; 1 top_N_items=IMF(df_pref_sample.values,df_conf_sample.values,X,Y)
  
  &lt;ipython-input-59-30994c977fdc&gt; in IMF(P, W, X, Y)
      105             Y[:,i] = np.linalg.solve(np.dot(X.T, np.dot(np.diag(Wi), X)) + lambda_ * np.eye(n_factors),
      106                                  np.dot(X.T, np.dot(np.diag(Wi), P[:, i])))
  --&gt; 107             print('{}th row of Y is completed'.format(i))
      108 
      109         weighted_errors.append(get_error(P,W,X,Y))
  
  \\dwdfhome01.wdf\Anaconda\lib\site-packages\ipykernel\iostream.pyc in write(self, string)
      315 
      316             is_child = (not self._is_master_process())
  --&gt; 317             self._buffer.write(string)
      318             if is_child:
      319                 # newlines imply flush in subprocesses
  
  ValueError: I/O operation on closed file
  </code></pre>
  
  <p>How to overcome this and get it done fast and run without error?</p>
  
  <p>Thanks</p>