[SciPy-User] masking an array ends up flattening it
Oleksandr Huziy
guziy.sasha at gmail.com
Tue Feb 28 17:32:55 EST 2012
Hi,
I don't think it is possible, and also not sure if the order will be conserved
when you select and reshape.
Why do you need it? Think what would you like to get in the case when
you have only one element True?
Cheers
--
Oleksandr Huziy
2012/2/28 Johann Cohen-Tanugi <johann.cohentanugi at gmail.com>:
> 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
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list