Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for index in union_set:
- loc = np.where(indices==index)
- dist = distances[loc]
- weight_array = np.zeros(len(indices))
- dist_array = np.zeros(len(indices))
- np.put(dist_array, loc[0], dist)
- np.put(weight_array, loc[0], weights[loc[0]])
- np.dot(weight_array, dist_array)
- >>> indices = np.array([[3,6,9], [4, 3, 8], [7, 3, 3]])
- >>> distances = np.array([[0.1, 0.2, 0.3], [0.2, 0.5, 0.8], [0.3, 0.4, 0.5]])
- >>> weights = np.array([0.6, 0.4, 0.9])
- >>> weight_array = np.zeros(len(indices))
- >>> dist_array = np.zeros(len(indices))
- >>> loc = np.where(indices==7)
- >>> loc
- (array([2]), array([0]))
- >>> dist = distances[loc]
- >>> dist
- array([0.3])
- >>> np.put(dist_array, loc[0], dist)
- >>> dist_array
- array([0. , 0. , 0.3])
- >>> np.put(weight_array, loc[0], weights[loc[0]])
- >>> weight_array
- array([0. , 0. , 0.9])
- >>> indices = np.array([[1,2,3], [2, 5, 9]])
- >>> distances = np.array([[0.1, 0.2, 0.3], [0.2, 0.4, 0.6]])
- >>> np.where(np.in1d(indices, 1))
- (array([0]),)
- >>> np.where(np.in1d(indices, 2))
- (array([1, 3]),)
- >>> np.where(np.in1d(indices, 9))
- (array([5]),)
- >>> distances.ravel()[np.where(np.in1d(indices, 9))]
- array([0.6])
- >>> distances.ravel()[np.where(np.in1d(indices, 2))]
- array([0.2, 0.2])
- >>> union_set = np.array(list(set().union(*indices)), dtype=np.uint32)
- >>> union_set
- array([1, 2, 3, 5, 9], dtype=uint32)
- >>> distances.ravel()[np.where(np.in1d(indices, union_set))]
- array([0.1, 0.2, 0.3, 0.2, 0.4, 0.6])
Add Comment
Please, Sign In to add comment