For the functions: hash_multi_plane and side_of_plane, I am using the code straight from the lab. I have been coding it my way for 2 days and it did not work. I could post the code I wrote but I am not sure if posting code is allowed. It was forbidden in the Machine Learning course that I recently completed. Anyway, I am getting an error from the test code (Copied straight from the assignment) shown below. Any help would be appreciated.
def hash_multi_plane_matrix(P, v, num_planes):*
** sides_matrix = side_of_plane_matrix(P, v) # Get the side of planes for P and v***
** hash_value = 0***
** for i in range(num_planes):***
** sign = sides_matrix[i].item() # Get the value inside the matrix cell***
** hash_i = 1 if sign >=0 else 0***
** hash_value += 2i * hash_i # sum 2^i * hash_i*
** return hash_value***
def side_of_plane(P, v):
** dotproduct = np.dot(P, v.T) # Get the dot product P * v’**
** sign_of_dot_product = np.sign(dotproduct) # The sign of the elements of the dotproduct matrix **
** sign_of_dot_product_scalar = sign_of_dot_product.item() # The value of the first item**
** return sign_of_dot_product_scalar**
UNQ_C20 (UNIQUE CELL IDENTIFIER, DO NOT EDIT)
# You do not have to input any code in this cell, but it is relevant to grading, so please do not change anything
planes = planes_l[0] # get one ‘universe’ of planes to test the function
tmp_hash_table, tmp_id_table = make_hash_table(document_vecs, planes)
print(f"The hash table at key 0 has {len(tmp_hash_table[0])} document vectors")
print(f"The id table at key 0 has {len(tmp_id_table[0])}")
print(f"The first 5 document indices stored at key 0 of are {tmp_id_table[0][0:5]}")
ERROR
ValueError Traceback (most recent call last)
in
2 # You do not have to input any code in this cell, but it is relevant to grading, so please do not change anything
3 planes = planes_l[0] # get one ‘universe’ of planes to test the function
----> 4 tmp_hash_table, tmp_id_table = make_hash_table(document_vecs, planes)
5
6 print(f"The hash table at key 0 has {len(tmp_hash_table[0])} document vectors")
in make_hash_table(vecs, planes, hash_value_of_vector)
37 for i, v in enumerate(vecs):
38 # calculate the hash value for the vector
—> 39 h = hash_value_of_vector(vecs[i], planes)
40
41 # store the vector into hash_table at key h,
in hash_value_of_vector(P_l, v)
4 print("i: ", i)
5 print("P: ", P)
----> 6 sign = side_of_plane(P,v)
7 print("sign: ", sign, )
8 hash_i = 1 if sign >=0 else 0
in side_of_plane(P, v)
4 sign_of_dot_product = np.sign(dotproduct) # The sign of the elements of the dotproduct matrix
5 print("sign_of_dot_product: ", sign_of_dot_product)
----> 6 sign_of_dot_product_scalar = sign_of_dot_product.item() # The value of the first item
7 print("sign_of_dot_product_scalar: ", sign_of_dot_product_scalar)
8 return sign_of_dot_product_scalar
ValueError: can only convert an array of size 1 to a Python scalar