本文整理汇总了Python中numpy.nanprod方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.nanprod方法的具体用法?Python numpy.nanprod怎么用?Python numpy.nanprod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.nanprod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __matmul__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanprod [as 别名]
def __matmul__(self, other):
if isinstance(other, Option):
return self @ Domain(other)
if self._is_array_option():
that = self._to_scalar_product()
else:
that = self
if other._is_array_option():
other = other._to_scalar_product()
if that._is_scalar_product() and other._is_scalar_product():
if len(that.cubes) == len(other.cubes):
cubes = [cube_1 + cube_2 for cube_1, cube_2 in zip(that.cubes, other.cubes)]
weights = np.nanprod(np.stack([that.weights, other.weights]), axis=0)
nan_mask = np.logical_and(np.isnan(that.weights), np.isnan(other.weights))
weights[nan_mask] = np.nan
return Domain(domain=cubes, weights=weights)
raise ValueError("The numbers of domain cubes must conincide.")
示例2: test_nanfunctions_matrices_general
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanprod [as 别名]
def test_nanfunctions_matrices_general():
# Check that it works and that type and
# shape are preserved
# 2018-04-29: moved here from core.tests.test_nanfunctions
mat = np.matrix(np.eye(3))
for f in (np.nanargmin, np.nanargmax, np.nansum, np.nanprod,
np.nanmean, np.nanvar, np.nanstd):
res = f(mat, axis=0)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (1, 3))
res = f(mat, axis=1)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (3, 1))
res = f(mat)
assert_(np.isscalar(res))
for f in np.nancumsum, np.nancumprod:
res = f(mat, axis=0)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (3, 3))
res = f(mat, axis=1)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (3, 3))
res = f(mat)
assert_(isinstance(res, np.matrix))
assert_(res.shape == (1, 3*3))
示例3: test_nanprod
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanprod [as 别名]
def test_nanprod(self):
tgt = np.prod(self.mat)
for mat in self.integer_arrays():
assert_equal(np.nanprod(mat), tgt)
示例4: test_empty
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanprod [as 别名]
def test_empty(self):
for f, tgt_value in zip([np.nansum, np.nanprod], [0, 1]):
mat = np.zeros((0, 3))
tgt = [tgt_value]*3
res = f(mat, axis=0)
assert_equal(res, tgt)
tgt = []
res = f(mat, axis=1)
assert_equal(res, tgt)
tgt = tgt_value
res = f(mat, axis=None)
assert_equal(res, tgt)
示例5: test_prod
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanprod [as 别名]
def test_prod(self):
self._check_stat_op('prod', np.prod, skipna_alternative=np.nanprod)
示例6: test_nanprod
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanprod [as 别名]
def test_nanprod(self):
self.check_funs(nanops.nanprod, np.prod, allow_str=False,
allow_date=False, allow_tdelta=False,
empty_targfunc=np.nanprod)
示例7: __mul__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanprod [as 别名]
def __mul__(self, other):
if isinstance(other, float) and np.isnan(other):
return self
if self.cubes is None:
result = other
elif isinstance(other, (int, float)):
result = self
weights = self.weights
weights[np.isnan(weights)] = 1
result.weights = weights * other
elif isinstance(other, Domain):
if other.cubes is None:
result = self
else:
res = list(product(self.cubes, other.cubes))
res = [item[0] + item[1] for item in res]
pairs = np.array(list(product(self.weights, other.weights)))
weights = np.array([np.nanprod(item) for item in pairs])
nan_mask = np.array([np.isnan(item).all() for item in pairs])
weights[nan_mask] = np.nan
result = Domain(res, weights=weights)
elif isinstance(other, Option):
result = self * Domain(other)
else:
raise TypeError('Arguments must be numeric, Domains or Options')
return result
示例8: nanprod
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nanprod [as 别名]
def nanprod(a, axis=None, dtype=None, out=None, keepdims=False):
"""Returns the product of an array along given axes treating Not a Numbers
(NaNs) as zero.
Args:
a (cupy.ndarray): Array to take product.
axis (int or sequence of ints): Axes along which the product is taken.
dtype: Data type specifier.
out (cupy.ndarray): Output array.
keepdims (bool): If ``True``, the specified axes are remained as axes
of length one.
Returns:
cupy.ndarray: The result array.
.. seealso:: :func:`numpy.nanprod`
"""
if _fusion_thread_local.is_fusing():
if keepdims:
raise NotImplementedError(
'cupy.nanprod does not support `keepdims` in fusion yet.')
if dtype is None:
func = _math._nanprod_auto_dtype
else:
func = _math._nanprod_keep_dtype
return _fusion_thread_local.call_reduction(
func, a, axis=axis, dtype=dtype, out=out)
# TODO(okuta): check type
return _math._nanprod(a, axis, dtype, out, keepdims)