what is a way to ask in python if a number actually exists and is not masked in python
Question: I have an numpy array with 13 invalid (logs of zeros) numbers that I have
masked and 3 valid numbers:

    
    
     [[-- -- -- --]
      [-- -- 0.0 0.3010299956639812]
      [-- -- -- 0.0]
      [-- -- -- --]]
    

I want to print out something like

    
    
      numlist=[]
        for item in array:
          numlist.append(num)
    
    for i in numlist:
       if i is not masked:
           print i
    

any suggestions?


Answer: You could use the
[MaskedArray.compressed](http://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.MaskedArray.compressed.html#numpy.ma.MaskedArray.compressed)
method to return all the non-masked data:

    
    
    print(arr.compressed())
    

To print one value per line:

    
    
    for val in arr.compressed():
        print(val)
    

* * *

If you wish to save space (instead of time), you could use `ravel` (as @DSM
points out). To iterate over the non-masked entries, you could use IT.izip to
loop over the values and the mask at the same time. For example,

    
    
    import itertools as IT
    import numpy as np
    
    arr = np.ma.masked_invalid(np.log(np.random.random((4,4))-0.5))
    arr1d = arr.ravel()
    for val, mask in IT.izip(arr1d, arr1d.mask):
        if not mask:
            print(val)
    

