Elegantly avoid columns containing NaNs? The next bit of code does exactly what i want it to do, but it is 'rather' unelegant and unpythonic, so the question is quite simple: how can this code be changed into something more elegant 

import numpy
from scipy.stats import nanmean
A = [[1, numpy.nan, 2],[2,3,4], [2,3,4], [numpy.nan, 5, 5]]
A1 = numpy.array(A)
print A1

def dosomething(d2):
    a0 = d2[0, :]
    a1 = d2[1, :]
    a2 = d2[2, :]
    dnan = ~numpy.isnan(a0+a1+a2)
    a01 = (a0-numpy.mean(a0[dnan]))/numpy.std(a0[dnan])
    a11 = (a1-numpy.mean(a1[dnan]))/numpy.std(a1[dnan])
    a21 = (a2-numpy.mean(a2[dnan]))/numpy.std(a2[dnan])
    l = nanmean(numpy.array([a01,a11,a21]), axis=0)
    return l

print dosomething(A1)


[[  1.  nan   2.]
[  2.   3.   4.]
[  2.   3.   4.]
[ nan   5.   5.]]

[-1.  0.  1.]


Edit: i simplified it a bit more
You can use d2[:, dnan] to select the wanted columns. (I'm assuming you want to process all rows unlike your current code)

def dosomething(d2):
    dnan = ~numpy.isnan(d2.sum(axis=0))
    validcols = d2[:, dnan]
    normalized = numpy.transpose((d2.T - numpy.mean(validcols, axis=1)) / numpy.std(validcols, axis=1))
    l = nanmean(normalized, axis=0)
    return l