[Numpy-discussion] Question about masked arrays

Gökhan Sever gokhansever at gmail.com
Sun Sep 19 13:19:48 EDT 2010


Hello,

Consider these two sets of container arrays --one defined as usual np array
the others as ma arrays:

    all_measured = np.ma.zeros((16, 18))
    all_predicted = np.ma.zeros((16, 18))
    all_measured2 = np.zeros((16, 18))
    all_predicted2 = np.zeros((16, 18))

I do a computation within a for loop to assign 16 set of measurements into a
length of 18 arrays (thus constructing a 2D array to perform overall
statistics and plotting.) For the simplicity I only show a portion of
all_measured and all_measured2 as:

all_measured
masked_array(data =
 [[512.632175 527.33373 565.36541 567.53967 593.86833 570.31319 574.40965
  582.72649 588.21336 618.48789 593.09007 620.33474 591.10203 611.06443
  655.60614 638.13193 626.71769 625.63584]
 [626.6435 -- -- 1183.67671 1206.82453 1183.13248 1162.5514 1180.70062
  1086.53246 1078.78711 997.1642 856.57159 645.35167 696.86947 778.40914
  816.03059 862.88297 901.7237] ...

all_measured2
array([[  512.632175  ,   527.33373   ,   565.36541   ,   567.53967   ,
          593.86833   ,   570.31319   ,   574.40965   ,   582.72649   ,
          588.21336   ,   618.48789   ,   593.09007   ,   620.33474   ,
          591.10203   ,   611.06443   ,   655.60614   ,   638.13193   ,
          626.71769   ,   625.63584   ],
       [  626.6435    ,     0.        ,     0.        ,  1183.67671   ,
         1206.82453   ,  1183.13248   ,  1162.5514    ,  1180.70062   ,
         1086.53246   ,  1078.78711   ,   997.1642    ,   856.57159   ,
          645.35167   ,   696.86947   ,   778.40914   ,   816.03059   ,
          862.88297   ,   901.7237    ],...

The issue is why masked arrays casted to regular numpy arrays as in
all_measured2 case? whereas a simple numpy function np.mean and ma
equivalent np.ma.mean yields same results on all_measured? Because the
former requires a priori knowledge about the type of arrays, however the
latter doesn't necessitate such restriction.

Hope this is clear. Thanks.

-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100919/e850cf31/attachment.html>


More information about the NumPy-Discussion mailing list