TypeError: unhashable type: 'numpy.ndarray' for nested lists

Hi All, I have 2 numpy arrays n and e which I want to iterate through but I get unhashable type: 'numpy.ndarray'. The shape of n is (112, 55, 55) and e is (112, 55).

Below are how both arrays look like:

n array
[[[4 1 0 … 0 1 0]
[2 0 2 … 4 1 1]
[1 2 1 … 3 0 0]

[0 4 4 … 3 0 1]
[3 1 0 … 2 2 4]
[3 1 1 … 0 4 3]]

[[2 4 0 … 1 2 4]
[0 0 0 … 0 0 0]
[4 0 0 … 0 2 3]

[0 0 0 … 1 4 0]
[0 2 2 … 4 2 4]
[4 2 3 … 2 0 0]]

[[3 0 1 … 3 2 4]
[3 0 2 … 3 2 3]
[3 2 0 … 2 1 1]

[3 0 4 … 1 2 4]
[2 2 1 … 2 1 0]
[4 0 2 … 3 0 4]]

[[1 3 0 … 3 3 2]
[3 0 4 … 3 0 0]
[4 0 2 … 4 2 4]

[0 1 4 … 3 0 1]
[3 2 2 … 2 0 0]
[2 0 3 … 1 0 4]]

[[4 3 2 … 0 1 1]
[1 1 4 … 0 0 4]
[0 2 2 … 1 3 3]

[1 0 1 … 3 2 3]
[4 1 4 … 2 4 2]
[1 0 3 … 1 0 3]]

[[4 0 2 … 4 0 0]
[4 0 0 … 1 0 0]
[2 0 2 … 1 2 3]

[4 1 0 … 1 0 0]
[0 0 2 … 2 0 1]
[3 3 1 … 1 4 0]]]

e array
[[3 0 5 … 5 5 1]
[4 8 6 … 4 8 7]
[5 8 0 … 3 6 0]

[0 8 0 … 6 0 8]
[3 9 0 … 0 8 1]
[7 3 2 … 2 3 2]]

The issue doesn’t seem to be PyTorch related so you might get a better and faster answer in e.g. StackOverflow.
In any case, if I understand your use case correctly, you would like to iterate he numpy arrays, which works fine:

n = np.random.randn(112, 55, 55) 
e = np.random.randn(112, 55)

for n_ in n:
    print(n_)
    
for e_ in e:
    print(e_)

Hi @ptrblck, I am using the line below to iterate through but getting unhashable type error:

m1 = [data.matrices2mol(n_, e_, strict=True) for n_, e_ in zip(n, e)]. Do you happen to know how to solve this?

I guess the error is raised in data.matrices2mol (which I don’t know how it’s implemented), as a plain list comprehension works:

m1 = [(n_, e_) for n_, e_ in zip(n, e)]