To solve this problem, one possible method is to replace the nan values with the mean of the columns. Here are several ways to solve this problem.
Method # 1: Using np.col mean
and np.take
|
Exit:
initial array [[1.3 2.5 3.6 nan] [2.6 3.3 nan 5.5] [2.1 3.2 5.4 6.5]] columns mean [2. 3. 4.5 6.] final array [[1.3 2.5 3.6 6.] [2.6 3.3 4.5 5.5] [2.1 3.2 5.4 6.5]]
Method # 2: Using np.ma
and np.where
|
Exit:
initial array [[1.3 2.5 3.6 nan] [2.6 3.3 nan 5.5] [2.1 3.2 5.4 6.5]] final array [[1.3 2.5 3.6 6.] [2.6 3.3 4.5 5.5] [2.1 3.2 5.4 6.5]]
Method # 3: Using Naive and zip
|
Exit:
initial array [[1.3 2.5 3.6 nan] [2.6 3.3 nan 5.5] [2.1 3.2 5.4 6.5]] final array [[1.3 2.5 3.6 6.] [2.6 3.3 4.5 5.5] [2.1 3.2 5.4 6.5]]