Guest User

Untitled

a guest
Dec 13th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. for index in union_set:
  2. loc = np.where(indices==index)
  3. dist = distances[loc]
  4. weight_array = np.zeros(len(indices))
  5. dist_array = np.zeros(len(indices))
  6. np.put(dist_array, loc[0], dist)
  7. np.put(weight_array, loc[0], weights[loc[0]])
  8. np.dot(weight_array, dist_array)
  9.  
  10. >>> indices = np.array([[3,6,9], [4, 3, 8], [7, 3, 3]])
  11. >>> distances = np.array([[0.1, 0.2, 0.3], [0.2, 0.5, 0.8], [0.3, 0.4, 0.5]])
  12. >>> weights = np.array([0.6, 0.4, 0.9])
  13. >>> weight_array = np.zeros(len(indices))
  14. >>> dist_array = np.zeros(len(indices))
  15. >>> loc = np.where(indices==7)
  16. >>> loc
  17. (array([2]), array([0]))
  18. >>> dist = distances[loc]
  19. >>> dist
  20. array([0.3])
  21. >>> np.put(dist_array, loc[0], dist)
  22. >>> dist_array
  23. array([0. , 0. , 0.3])
  24. >>> np.put(weight_array, loc[0], weights[loc[0]])
  25. >>> weight_array
  26. array([0. , 0. , 0.9])
  27.  
  28. >>> indices = np.array([[1,2,3], [2, 5, 9]])
  29. >>> distances = np.array([[0.1, 0.2, 0.3], [0.2, 0.4, 0.6]])
  30. >>> np.where(np.in1d(indices, 1))
  31. (array([0]),)
  32. >>> np.where(np.in1d(indices, 2))
  33. (array([1, 3]),)
  34. >>> np.where(np.in1d(indices, 9))
  35. (array([5]),)
  36. >>> distances.ravel()[np.where(np.in1d(indices, 9))]
  37. array([0.6])
  38. >>> distances.ravel()[np.where(np.in1d(indices, 2))]
  39. array([0.2, 0.2])
  40.  
  41. >>> union_set = np.array(list(set().union(*indices)), dtype=np.uint32)
  42. >>> union_set
  43. array([1, 2, 3, 5, 9], dtype=uint32)
  44. >>> distances.ravel()[np.where(np.in1d(indices, union_set))]
  45. array([0.1, 0.2, 0.3, 0.2, 0.4, 0.6])
Add Comment
Please, Sign In to add comment