title: Convert text document to numpy array of ASCII numbers in python
body: <p>I have a large plain text document (UTF-8) that contains letters, numbers, spaces, and special characters etc. </p>
  
  <p>I want to convert all the individual characters in the text document into numbers, and then represent the document as a numpy array. </p>
  
  <p>Can I use the inbuilt python ord() function for this? </p>
  
  <p>My understanding is that it returns an integer representing the Unicode code point of the character, but only takes on in one character at a time and I'm wondering if there's a better way to convert a large text document to numbers. </p>
  
  <p>Or can I just iterate through the entire document with the ord() function? </p>
  
  <p><strong>edit</strong></p>
  
  <p>I basically want to do something exactly like this! but natively in python <a href="https://www.browserling.com/tools/text-to-ascii" rel="nofollow noreferrer">https://www.browserling.com/tools/text-to-ascii</a></p>
  
  <p>This is what I currently have</p>
  
  <pre><code>def convert_to_ascii(text):
      return ",".join(str(ord(char)) for char in text)
  
  with open('test.txt', 'r') as myfile:
      data = myfile.read()
  
  convert_to_ascii(data)
  
  values = [int(i) for i in x.split(',')] 
  
  array = np.array(values)
  </code></pre>
  
  <p>Is there a better way to do this?</p>