title: UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
body: <p>I'm trying to write quite a complicated Python program, but it's mostly done. I am having trouble with just one tiny little detail.</p>
  
  <p>The problematic code section is this:</p>
  
  <pre><code>newData = kmeans.sampleNewData(200, means, covariances, priors)
  
  newData = newData.astype(str)
  ...loops and logic and stuff...
  newData[i, j] = columnsList[j][(indexList[j]).index(closestFit)]
  </code></pre>
  
  <p>Basically, <code>newData</code> is a numpy matrix size 200 by 4, filled with numbers of type float. I then convert them to strings use the <code>astype</code> method.</p>
  
  <p>I then try to put this <code>columnsList[j][(indexList[j]).index(closestFit)]</code> which is some string, into an entry of <code>newData</code>.</p>
  
  <p>The problem is that <code>columnsList[j][(indexList[j]).index(closestFit)]</code> is not necessarily English. It could for example be hebrew. In which case - I get the error </p>
  
  <blockquote>
    <p>UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)</p>
  </blockquote>
  
  <p>It is worth noting that I have written <code># -*- coding: utf-8 -*-</code> so we are encoding in utf-8, and when I print <code>columnsList[j][(indexList[j]).index(closestFit)]</code> it indeed prints the correct value. So we can print it. But for some reason I can't put it into the <code>newData</code> matrix.</p>