oversample_nan

oversample_nan(arr: ndarray, func: callable, axis: int = 1, copy: bool = True, seed: int = None) ndarray[source][source]

Oversample nan rows using func

Parameters:
  • arr (array) – The data to oversample.

  • func (callable) – The function to use to oversample the data.

  • axis (int) – The axis along which to apply func.

  • copy (bool) – Whether to copy the data before oversampling.

  • seed (int)

Return type:

ndarray

Examples

>>> np.random.seed(0)
>>> arr = np.array([[1, 2], [4, 5], [7, 8],
... [float("nan"), float("nan")]])
>>> oversample_nan(arr, norm, 0)
array([[1.        , 2.        ],
       [4.        , 5.        ],
       [7.        , 8.        ],
       [8.32102813, 5.98018098]])
>>> oversample_nan(arr, mixup, 0, seed=42)
array([[1.        , 2.        ],
       [4.        , 5.        ],
       [7.        , 8.        ],
       [5.24946679, 6.24946679]])
>>> arr3 = np.arange(24, dtype=float).reshape(2, 3, 4)
>>> arr3[0, 2, :] = [float("nan")] * 4
>>> oversample_nan(arr3, mixup, 1, seed=42)
array([[[ 0.        ,  1.        ,  2.        ,  3.        ],
        [ 4.        ,  5.        ,  6.        ,  7.        ],
        [ 2.33404428,  3.33404428,  4.33404428,  5.33404428]],

       [[12.        , 13.        , 14.        , 15.        ],
        [16.        , 17.        , 18.        , 19.        ],
        [20.        , 21.        , 22.        , 23.        ]]])
>>> oversample_nan(arr3, norm, 1)
array([[[ 0.        ,  1.        ,  2.        ,  3.        ],
        [ 4.        ,  5.        ,  6.        ,  7.        ],
        [ 3.95747597,  7.4817864 ,  7.73511598,  3.04544424]],

       [[12.        , 13.        , 14.        , 15.        ],
        [16.        , 17.        , 18.        , 19.        ],
        [20.        , 21.        , 22.        , 23.        ]]])