Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. Sample Dog Cat Tarsier
  2. A47 1 7 2
  3. A48 3 3 4
  4. A51 2 1 8
  5. A53 0 0 0
  6. A54 1 7 2
  7. A57 0 0 10
  8.  
  9. Cat Tarsier
  10. A47 7 2
  11.  
  12. struct row{
  13. char *name;
  14. int animal[3]; //id 0 is dog, 1 is cat and 2 is tarsier
  15. }
  16.  
  17. int i;
  18. float sum=0; //we need float to force the result to be float
  19. for (i=0;i<3;i++){
  20. sum += row.animal[i]; //count the total row population
  21. }
  22. for (i=0;i<3;i++){ //for every animal
  23. if (row.animal[i]/sum <= 0.1){ //if this animal is equal or less than 10% of the row population
  24. row.animal[i]=0; //set his population to 0
  25. }
  26. }
  27.  
  28. import csv
  29.  
  30. def getvals(file):
  31. """
  32. gets the val's from a file of whitespace separated values, and
  33. turns them into easy to use Python var's
  34. """
  35. samples = csv.reader(open(file))
  36. s = []
  37. n = 0
  38. for row in samples:
  39. r = [row[0].split()]
  40. s += r
  41. n+=1
  42. return s
  43.  
  44. [
  45. ['Sample', 'Dog', 'Cat', 'Tarsier'],
  46. ['A47', '1', '7', '2'],
  47. ['A48', '3', '3', '4'],
  48. ['A51', '2', '1', '8'],
  49. ['A53', '0', '0', '0'],
  50. ['A54', '1', '7', '2'],
  51. ['A57', '0', '0', '10']
  52. ]
  53.  
  54. >>> data = np.genfromtxt('data.txt', delimiter="t", names=True, dtype=None)
  55.  
  56. data = array([('A47', 1, 7, 2), ('A48', 3, 3, 4), ('A51', 2, 1, 8),
  57. ('A53', 0, 0, 0), ('A54', 1, 7, 2), ('A57', 0, 0, 10)],
  58. dtype=[('Sample', '|S3'), ('Dog', '<i8'), ('Cat', '<i8'), ('Tarsier', '<i8')])
  59.  
  60. >>> data[["Cat","Tarsier"]]
  61. array([(7, 2), (3, 4), (1, 8), (0, 0), (7, 2), (0, 10)],
  62. dtype=[('Cat', '<i8'), ('Tarsier', '<i8')])
  63.  
  64. >>> data[[0,2]]
  65. array([('A47', 1, 7, 2), ('A51', 2, 1, 8)],
  66. dtype=[('Sample', '|S3'), ('Dog', '<i8'), ('Cat', '<i8'), ('Tarsier', '<i8')])
  67.  
  68. >>> data["Dog"].mean()
  69. 1.1666667
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement