nanprod#

ivy.nanprod(a, /, *, axis=None, keepdims=False, dtype=None, out=None, initial=None, where=None)[source]#

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

Parameters:
  • a (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – Axis or axes along which the product is computed. The default is to compute the product of the flattened array.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – The desired data type of returned array. Default is None.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

  • keepdims (Optional[bool], default: False) – If this is set to 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.

  • initial (Optional[Union[int, float, complex]], default: None) – The starting value for this product.

  • where (Optional[Array], default: None) – Elements to include in the product

Return type:

Array

Returns:

ret – The product of array elements over a given axis treating Not a Numbers (NaNs) as ones

Functional Examples

>>> a = ivy.array([[1, ivy.nan], [3, 4]])
>>> ivy.nanprod(a)
12.0
>>> ivy.nanprod(a, axis=0)
[3. 4.]
>>> ivy.nanprod(a, axis=0, keepdims=True)
[[3. 4.]]
Array.nanprod(self, /, *, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=None)[source]#

ivy.Array instance method variant of ivy.nanprod. This method simply wraps the function, and so the docstring for ivy.prod also applies to this method with minimal changes.

Parameters:
  • self (Array) – Input array.

  • axis (Optional[Union[int, Tuple[int]]], default: None) – Axis or axes along which the product is computed. The default is to compute the product of the flattened array.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – The desired data type of returned array. Default is None.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

  • keepdims (Optional[bool], default: False) – If this is set to 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.

  • initial (Optional[Union[int, float, complex]], default: None) – The starting value for this product.

  • where (Optional[Array], default: None) – Elements to include in the product

Return type:

Array

Returns:

ret – The product of array elements over a given axis treating Not a Numbers (NaNs) as ones

Examples

>>> a = ivy.array([[1, 2], [3, ivy.nan]])
>>> a.nanprod(a)
6.0
>>> a.nanprod(a, axis=0)
ivy.array([3., 2.])
Container.nanprod(self, /, *, axis=None, dtype=None, keepdims=False, out=None, initial=None, where=None)[source]#

ivy.Container instance method variant of ivy.nanprod. This method simply wraps the function, and so the docstring for ivy.nanprod also applies to this method with minimal changes.

Parameters:
  • self (Container) – Input container including arrays.

  • axis (Optional[Union[int, Tuple[int], Container]], default: None) – Axis or axes along which the product is computed. The default is to compute the product of the flattened array.

  • dtype (Optional[Union[Dtype, NativeDtype, Container]], default: None) – The desired data type of returned array. Default is None.

  • out (Optional[Container], default: None) – optional output array, for writing the result to.

  • keepdims (Optional[Union[bool, Container]], default: False) – If this is set to 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.

  • initial (Optional[Union[int, float, complex, Container]], default: None) – The starting value for this product.

  • where (Optional[Union[Array, Container]], default: None) – Elements to include in the product

Return type:

Container

Returns:

ret – The product of array elements over a given axis treating Not a Numbers (NaNs) as ones

Examples

>>> a = ivy.Container(x=ivy.array([[1, 2], [3, ivy.nan]]),                                y=ivy.array([[ivy.nan, 1, 2], [1, 2, 3]])
>>> a.nanprod()
{
    x: 12.0
    y: 12.0
}