forked from uchicago-cs/python-practice-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_matching_indices.py
43 lines (32 loc) · 1.28 KB
/
compute_matching_indices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def compute_matching_indices(x, y):
"""
Returns a new array consisting of the indices where
x == y.
Input:
x: 1-dimensional array
y: 1-dimensional array
Returns: a sorted array of the indices where x[i] == y[i]
Note that the returned array must be one-dimensional!
"""
# YOUR CODE HERE
# Replace None with an appropriate return value
return None
#############################################################
### ###
### Testing code. ###
### !!! DO NOT MODIFY ANY CODE BELOW THIS POINT !!! ###
### ###
#############################################################
import sys
import numpy as np
sys.path.append('../')
import test_utils as utils
def test_compute_matching_indices():
x = np.array([1, 2, 3, 4])
y = np.array([1, 5, 3, 2])
recreate_msg = utils.gen_recreate_msg('compute_matching_indices', x, y)
result = compute_matching_indices(x, y)
utils.check_none(result, recreate_msg)
utils.check_is_ndarray(result, recreate_msg)
utils.check_dtype(result, int, recreate_msg)
utils.check_array_equal(result, np.array([0, 2]), recreate_msg)