0

I have a set of *.mat files and I can read them easily as stated here. Each file is in shape (1,1) and it look like the following:

[[(array([[  20913,   28913,   36913,   44913,   52914,   60914]], dtype=int32), array([[ 1,  1, -1,  1,  1,  1]], dtype=int16))]]

In this case, how can I extract each array?

Dave
  • 554
  • 1
  • 6
  • 13

1 Answers1

1

By reproducing the same nested list you have, it's become easy to understand:

import numpy as np

arr1 = np.array([[20913, 28913, 36913, 44913, 52914, 60914]], dtype=np.int32)
arr2 = np.array([[1, 1, -1, 1, 1, 1]], dtype=np.int16)

lst = [[arr1, arr2]]
print(lst)

The above is your lst structure, also arr1 and arr2 are (1,1) :

nested1 = lst[0][0].tolist()[0]
nested2 = lst[0][1].tolist()[0]

print(nested1)
print(nested2)

first [0] to get the [arr1, arr2]. Next bracket is for arr1 and arr2 respectfully.

with tolist() you can convert them to python's built-in list type and because they are (1,1) you need the first item which means [0].

S.B
  • 13,077
  • 10
  • 22
  • 49