dpnp.nanprod

dpnp.nanprod(a, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True)[source]

Return the product of array elements over a given axis treating Not a Numbers (NaNs) as ones.

For full documentation refer to numpy.nanprod.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Input array.

  • axis ({None, int or tuple of ints}, optional) -- Axis or axes along which the product is computed. The default is to compute the product of the flattened array. Default: None.

  • dtype ({None, dtype}, optional) -- The type of the returned array and of the accumulator in which the elements are multiplied. By default, the dtype of a is used. An exception is when a has an integer type with less precision than the platform (u)intp. In that case, the default will be either (u)int32 or (u)int64 depending on whether the platform is 32 or 64 bits. For inexact inputs, dtype must be inexact. Default: None.

  • out ({None, dpnp.ndarray, usm_ndarray}, optional) -- Alternate output array in which to place the result. If provided, it must have the same shape as the expected output, but the type will be cast if necessary. The casting of NaN to integer can yield unexpected results. Default: None.

  • keepdims ({None, bool}, optional) -- If True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a. Default: False.

Returns:

out -- A new array holding the result is returned unless out is specified, in which case it is returned.

Return type:

dpnp.ndarray

See also

dpnp.prod

Returns product across array propagating NaNs.

dpnp.isnan

Test element-wise for NaN and return result as a boolean array.

Limitations

Input array is only supported as either dpnp.ndarray or dpctl.tensor.usm_ndarray. Parameters initial, and where are only supported with their default values. Otherwise the function will be executed sequentially on CPU. Input array data types are limited by supported DPNP Available array data types.

Examples

>>> import dpnp as np
>>> np.nanprod(np.array(1))
array(1)
>>> np.nanprod(np.array([1]))
array(1)
>>> np.nanprod(np.array([1, np.nan]))
array(1.0)
>>> a = np.array([[1, 2], [3, np.nan]])
>>> np.nanprod(a)
array(6.0)
>>> np.nanprod(a, axis=0)
array([3., 2.])