Problem in nearest_neighbor function

I am not able to reverse the sorted_ids array.
I used the ‘Hint’ suggestion tmp[::-1] but i don’t get the intended result.
There must be something somewhere in my code causing this but I haven’t found it.
I need a suggestion for how to debug this.

Do you obtain the sorted array? If so the array[::-1] should reverse it.

If you cant obtain the sorted array then the problems lies in previous sections. Also make sure that the array is not a tf.tensor, I am mot sure if the operation will work with tensors.

Yes, I get the sorted array.
If I comment out the line to reverse the array, output is:
[[9 9 9]
[1 0 5]
[2 0 1]]

Expected Output:
[[2 0 1] [1 0 5] [9 9 9]]

If I uncomment the reverse line:

Reverse the order of the sorted_ids array

sorted_ids = sorted_ids[::-1]

The output is:
[[ 9 9 9]
[ 6 -9 5]
[-2 5 3]]

Problem solved.
Getting correct output now.
Got a fresh notebook and started over.
Thanks for your help.

1 Like

I am facing the same problem :frowning:
How did you get a fresh notebook ?

Or if there is another solution …
@gent.spah help please!

Hi @Huda_Mohammed_Alamri

Here are the instructions how to refresh your workspace.

k_idx should be sorted ids up to k values (because you sort ascending) and not the last k values.


Thank you so much @arvyzukai, it works now :pray:t2:

1 Like

I am still facing this issue after refreshing the work space. Do I also need to deleted the related files, or before refreshing the workspaces should I close the browser?

Hi @Sonu_Chhabra
If you are facing this issue after refreshing the workplace then please go to that assignment home directory (via navigate button from top) and manually delete all materials including the .py files, assignment .ipynb file, and so on. After that refresh the assignment again.

me also having same problem .what can i do

i am facing the same problem . i can’t able refresh it . the instruction link you provided is direct to another course’s home page

Please check this post.

iam still facing that issue the ouput is
[[ 9 9 9]
[ 6 -9 5]
[-2 5 3]]
expected output
[[2 0 1]
[1 0 5]
[9 9 9]]

Please start a new post and share your full error (not code).