I'd like to get some help understanding vectorized operations on multi-dimensional arrays. Specifically, I've got a problem and some code that I t...
For further actions, you may consider blocking this person and/or reporting abuse
Without getting into the weeds, here are my high-level thoughts:
Given the input data and approach, are you sure that you should be able to get accuracy in the
0.94
range? Does the exercise indicate you should be able to get results like this using the algorithm approach you tried?This ☝️ point brings up a second important point: it would be useful for you to decompose the problem into its key components and check each of those components separately. Are you sure the loading and broadcasting steps are working like you think it should? Have you tried your
distance
function on some simple data and got the result you expected? Finally, if all of the above are working as expected, could you put together some data which should receive 100% accuracy, and then test that out?By looking at each piece individually (ideally with a light-weight unit test) you can start to narrow down the list of potential causes.
Thanks for your help. I had been putting off tests, but that was the next step in the plan.
Actually, running through a much simpler case in a REPL ended up doing it for me. See my comment about my solution.
But your comments about going back to debugging basics and slowly and methodically validating one piece of logic at a time were what put me back on the right track, so thanks!
Glad you were able to figure it out, nice work!
I've got an article in the works that walks through this in more detail, but I wanted to post my solution in case somebody ran into the same or similar issue.
The main problem I was having was using the
reshape
method is the wrong one. It would give me the right dimensions, but it jumbled up all of the individual numbers and didn't keep the "records" together.After doing some experimenting in a REPL with simpler cases, I discovered that what I really wanted was
swapaxis
. This keeps the numbers in the correct order, but allows you to pivot an array into other dimensions (e.g. roll your 2D array into a plane in the third dimension).So what I ended up with is:
Ah, is this column-major vs row-major ordering issue?
Yeah or maybe the multidimensional version of that, although I tried numpy’s different ordering strategies and none seemed to work quite right.