Guest User

Untitled

a guest
Jan 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. numpy.loadtxt(
  2. fname,
  3. dtype=<type 'float'>,
  4. comments='#',
  5. delimiter=None,
  6. converters=None,
  7. skiprows=0,
  8. usecols=None,
  9. unpack=False,
  10. ndmin=0
  11. )
  12. Load data from a text file.
  13. ...
  14. usecols : sequence, optional Which columns to read, with 0 being
  15. the first. For example, usecols = (1,4,5) will extract the
  16. 2nd, 5th and 6th columns. The default, None, results in all
  17. columns being read.
  18.  
  19. 100 test1
  20. 200 test2
  21. 300 test3
  22.  
  23. $ python -c "import numpy as np;np.loadtxt('test.txt')"
  24. Traceback (most recent call last):
  25. ...
  26. items = [conv(val) for (conv, val) in zip(converters, vals)]
  27. ValueError: could not convert string to float: test1
  28.  
  29. $ python -c "import numpy as np;print np.loadtxt('test.txt', usecols=(0,))"
  30. [ 100. 200. 300.]
  31.  
  32. numpy.loadtxt('input_file.txt', dtype=str, usecols=(1,2,3,4))
  33.  
  34. array([['MAX', 'Footprint', 'Center-X', 'Center-Y'],
  35. ['"100-0009"', '"1206', '-', 'CAPACITOR"'],
  36. ['"100-0009"', '"1206', '-', 'CAPACITOR"'],
  37. ['"100-0009"', '"1206', '-', 'CAPACITOR"'],
  38. ['"100-0009"', '"1206', '-', 'CAPACITOR"'],
  39. ['"100-0009"', '"1206', '-', 'CAPACITOR"'],
  40. ['"100-0009"', '"1206', '-', 'CAPACITOR"']],
  41. dtype='|S10')
Add Comment
Please, Sign In to add comment