[SciPy-User] masking an array ends up flattening it

Johann Cohen-Tanugi johann.cohentanugi@gmail....
Tue Feb 28 16:23:46 CST 2012


Hello,
I have the following:
In [145]: m
Out[145]:
array([[  1.82243247e-23,  -5.53103453e-14,   4.32071039e-13,
           0.00000000e+00],
        [ -5.52425949e-14,   6.26697129e-02,  -5.12076585e-02,
           0.00000000e+00],
        [  4.31598429e-13,  -5.12102340e-02,   6.27539118e-02,
           0.00000000e+00],
        [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
           1.00000000e+10]])

In [146]: mask
Out[146]:
array([[ True,  True,  True, False],
        [ True,  True,  True, False],
        [ True,  True,  True, False],
        [False, False, False, False]], dtype=bool)

Naively, I thought I would end up with a (3,3) shaped array when 
applying the mask to m, but instead I get :

In [147]: m[mask]
Out[147]:
array([  1.82243247e-23,  -5.53103453e-14,   4.32071039e-13,
         -5.52425949e-14,   6.26697129e-02,  -5.12076585e-02,
          4.31598429e-13,  -5.12102340e-02,   6.27539118e-02])

In [148]: m[mask].shape
Out[148]: (9,)

Is there another way to proceed and get directly the (3,3) shaped masked 
array, or do I need to reshape it by hand?

thanks a lot in advance,
Johann


More information about the SciPy-User mailing list