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
None
You can 'upcast' the array to numpy's float64 dtype and then use numpy's nanmean method as in the following example:
import numpy as np arr = [1,2,3, None] arr2 = np.array(arr, dtype=np.float64) print(arr2) # [ 1. 2. 3. nan] print(np.nanmean(arr2)) # 2.0