Khaled
Khaled

Reputation: 1

creat a dictionary from list of 3D tensor and a list

I have a list of 3D tensors values called x_train I want to create a dictionary by using them as key for another list.

x_train=np.array(pair_code).reshape(-1, 1, 23, 4) 


mat_gen={}    
for x in range(len(x_train)):
    mat_gen[x_train[x]]=gene_seq[x]

`

but I get

--> 143 mat_gen[x_train[x][0]]=gene_seq[x] 144 145

TypeError: unhashable type: 'numpy.ndarray'

Upvotes: 0

Views: 111

Answers (1)

user13809386
user13809386

Reputation:

In Python hashables should be immutable. That means you can use int, string, float, tuples as key of dictionaries. But you cannot use arrays, numpy arrays, lists, ... as key element of a dictionary

Upvotes: 1

Related Questions