0

I am new to python and I am trying to index a bunch of pcd files(each file is essentially an n*3 array) by matching them with their classtype. certain file is class 1, 2, 3 and so on. WHen i try to run it I am getting an unhashable numpy.ndarrayerror. Since I have a row of files that I need to load and index, how should I proceed?

path= glob.glob("path/to/pcd/folder/*.pcd")
data_dict=dict()
for i in range(len(list(path):
    currentPath = path[i]
    classtype=currentPath[-5:]
    classtype=classtype[0]
    p = pcl.load(path[i])
    a = np.asarray(p)
    data_dict[a]=classtype
    
    

15
  • 1
    One problem is that you have the dict lookup backward. In line three you have ”Object”:a which is to say the key is obeject and the value is a. If you want to get a you should do dict[“Object”] rather than dict[a] Commented Aug 20, 2018 at 15:37
  • 1
    You should review the dict documentation Commented Aug 20, 2018 at 15:38
  • Hey @K.Dackow, I tried your solution and now my loop is going through iterations but it is overwriting the previous array. The relationship I am looking to establish in my dictionary is a:classtype. Shall I declare it differently? Commented Aug 20, 2018 at 15:41
  • 1
    What do you mean a:classtype? Right now classtype is just a string so it does not actually represent the type of the object, it is literally just classtype. But yes, if you want to dictionary to map a to classtype then switch the order of them in the declaration Commented Aug 20, 2018 at 15:42
  • But what is your objective? Could you clarify what you want the dict to do? Do you want each element in the input array to be an element in the dictionary mapping to its classtype? Commented Aug 20, 2018 at 15:43

1 Answer 1

1

To put all PCLs in a dictionary so that you can look up their corresponding Classtypes, you need to do something like this:

my_dict = dict() # declaring empty dictionary
for point_cloud in pcl_list:
    my_dict[point_cloud] = classtype #somewhere in the loop you need to set what classtype is for each specific point_cloud

Now you can do this:

>> my_dict[some_pcl]
<the corresponding classtype>
Sign up to request clarification or add additional context in comments.

8 Comments

I think review of the documentation will help me understand it much better. I tried your code but it still gave me the unhashable numpy.ndarrayerror.
What line is throwing that error? My code isn’t full code and will not work, because i don’t know exactly the data structures you are working with. However, it conceptually shows how to iterate through something to put them in a dictionary
And what is causing the error? What line or object? Could you post more of your code in the question?
I have added the entire code. The error is in the last line of the code. Hope it helps !
Rename dict to something else. You are overriding the builtin dictionary methods by naming a variable dict! I don’t know if that will fix the problem completely, but it does need to be changed
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.