I have a large numpy void array loaded from a matlab struct. I can access the arrays stored inside the main array, but accessing their shape returns '()'. Accessing their length returns the error: len() of unsized object. Is there a way for me to access the shape of the sub-arrays?
arr = scipy.io.loadmat('mymatfile.mat', squeeze_me=True)
sub_arr = arr['a'][0]['b']['c']
print(sub_arr)
print(sub_arr.shape)
print(len(sub_arr))
returns: [[0 0 0 0] [0 0 0 0]] ()
TypeError: len() of unsized object
Solution: sub_arr.item() returns a sized array
len
of an 0d array produces this error:
In [77]: x = np.array(123)
In [78]: x
Out[78]: array(123)
In [79]: x.shape
Out[79]: ()
In [80]: len(x)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-80-a7f4a5366567> in <module>()
----> 1 len(x)
TypeError: len() of unsized object
loadmat
uses object dtype arrays to represent MATLAB cells and struct.
What's the dtype
of sub_arr
? You may need to use sub_arr.item()or
sub_arr[()]` to extract that item from the object layer.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments