W4 Assignment - Problem with hash_value_of_vector

Hi all,
My implemetation of hash_value_of_vector passed the first test

The hash value for this vector, and the set of planes at index 0, is 768

but when executing

Test your function


I get the following error:

in hash_value_of_vector(v, planes)
41 for i in range(n_planes):
42 # increment the hash value by 2^i * h_i
—> 43 hash_value += np.power(2,i) * h[:,i]
45 ### END CODE HERE ###

IndexError: index 8 is out of bounds for axis 1 with size 8

No clue. It seems that vector is of dim (1,8), though it should be (1,10). Please, any piece of advice will be most welcomed.

Hey @francisco_coronado,
Welcome to the community. The thing to look here is the line of code h = np.squeeze(h). It converts h from a 2D array into a 1D array. Therefore, for indexing h, you have to do h[i] and not h[:, i]. You can read more about this function here. I hope this helps.


Many thanks @Elemento for the answer. I finally found that it was a problem with the range of the loop. I wrote range(NUM_PLANES) where the right one was range(h.shape[1]).

That’s weird :joy: What I meant was something different, but whatever solves your query, after all, in programming, there is never a single method to implement something.