Anouk Bosmann
Anouk Bosmann

Reputation: 1

Dimensions of array don't match

I have a numpy array and when I print it i get this output. But I expected to get (105835, 99, 13) as output when printing the print(feat.shape) and was expecting feat to have 3 dimensions.

print(feat.ndim)
print(feat.shape)
print(feat.size)
print(feat[1].ndim)    
print(feat[1].shape)    
print(feat[1].size)`    

1    
(105835,)    
105835    
2    
(99, 13)    
1287

I don't know how to reduce this. But feat is a MFCC feature. If I print feat this is what I get.

array([array([[-1.0160675e+01, -1.3804866e+01,  9.1880971e-01, ...,
     1.5415058e+00,  1.1875046e-02, -5.8664594e+00],
   [-9.9697800e+00, -1.3823588e+01, -7.0778362e-02, ...,
     1.5948311e+00,  4.3481258e-01, -5.1646194e+00],
   [-9.9518738e+00, -1.2771760e+01, -1.2623003e-01, ...,
     3.4290311e+00,  2.7361808e+00, -6.0621500e+00],
   ...,
   [-11.605266 ,  -7.1909204, -33.44656  , ..., -11.974911 ,
     12.825395 ,  10.635098 ],
   [-11.769397 ,  -9.340318 , -34.413307 , ..., -10.077869 ,
      8.821722 ,   7.704534 ],
   [-12.301968 , -10.67318  , -32.46104  , ...,  -6.829077 ,
     15.29837  ,  13.100596 ]], dtype=float32)], dtype=object)

Upvotes: 0

Views: 381

Answers (1)

B. M.
B. M.

Reputation: 18628

the same structure can be create in a more simple way :

ain=rand(2,2)
a=ndarray(3,dtype=object)
a[:] = [ain]*3

#array([array([[ 0.14,  0.56],
#              [ 0.9 ,  0.9 ]]),
#       array([[ 0.14,  0.56],
#              [ 0.9 ,  0.9 ]]),
#       array([[ 0.14,  0.56],
#              [ 0.9 ,  0.9 ]])], dtype=object)

The problem arise because a.dtype is object. You can reconstruct your data by :

a= array(list(a))

#array([
#   [[ 0.14,  0.56],
#    [ 0.9 ,  0.9 ]],

#   [[ 0.14,  0.56],
#    [ 0.9 ,  0.9 ]],

#   [[ 0.14,  0.56],
#    [ 0.9 ,  0.9 ]]])

With will have the float type inherited from the base dtype.

Upvotes: 2

Related Questions