How to use numpy with 'None' value in Python?

后端 未结 7 2356
甜味超标
甜味超标 2020-12-18 18:14

I\'d like to calculate the mean of an array in Python in this form:

Matrice = [1, 2, None]

I\'d just like to have my None valu

相关标签:
7条回答
  • 2020-12-18 18:51

    You are looking for masked arrays. Here's an example.

    import MA
    a = MA.array([1, 2, None], mask = [0, 0, 1])
    print "average =", MA.average(a)
    

    Unfortunately, masked arrays aren't thoroughly supported in numpy, so you've got to look around to see what can and can't be done with them.

    0 讨论(0)
提交回复
热议问题