title: How to make a matrix of 0 and 1?
body: <p>I have a file containing some lines. Each line contains a Persian sentence, a tab and then an English word, which shows each sentence's class. I have to extract the 1000 most frequent words from this file and then I want to make a matrix. The columns of this matrix are the classes of the file (some files have 2 classes, some 3 and some, more) and the rows are these 1000 words (as like as the picture below (it's a small sample with English words but mine are Persian. d1 to d5 are classes)). I have to check each 1000 words in each class, if it exist there, add 1 to matrix (in its own place), and if not, add 0. How can I make such a matrix?</p>
  
  <pre><code>def makeMatrix(file):
      with open (file, encoding = "utf-8") as f1:
          for line in f1:
              line = line.strip().split("\t")
              lin = line[0].split()
              for word in lin:
               ????????????
  </code></pre>
  
  <p>sample matrix:</p>
  
  <p><a href="https://i.stack.imgur.com/ABdLY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ABdLY.png" alt="enter image description here"></a></p>
  
  <p>sample file:
  <a href="https://www.dropbox.com/s/fx33cac3qemizmj/train1.txt?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/fx33cac3qemizmj/train1.txt?dl=0</a>
  <a href="https://i.stack.imgur.com/jXvgs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jXvgs.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/aiCEo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aiCEo.png" alt="enter image description here"></a></p>