本文整理汇总了Python中numpy.nancumprod方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.nancumprod方法的具体用法?Python numpy.nancumprod怎么用?Python numpy.nancumprod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.nancumprod方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNanCumReduction
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nancumprod [as 别名]
def testNanCumReduction(self):
raw = np.random.randint(5, size=(8, 8, 8))
raw[:2, 2:4, 4:6] = np.nan
arr = tensor(raw, chunk_size=3)
res1 = self.executor.execute_tensor(nancumsum(arr, axis=1), concat=True)
res2 = self.executor.execute_tensor(nancumprod(arr, axis=1), concat=True)
expected1 = np.nancumsum(raw, axis=1)
expected2 = np.nancumprod(raw, axis=1)
np.testing.assert_array_equal(res1[0], expected1)
np.testing.assert_array_equal(res2[0], expected2)
raw = sps.random(8, 8, density=.1, format='lil')
raw[:2, 2:4] = np.nan
arr = tensor(raw, chunk_size=3)
res1 = self.executor.execute_tensor(nancumsum(arr, axis=1), concat=True)[0]
res2 = self.executor.execute_tensor(nancumprod(arr, axis=1), concat=True)[0]
expected1 = np.nancumsum(raw.A, axis=1)
expected2 = np.nancumprod(raw.A, axis=1)
self.assertTrue(np.allclose(res1, expected1))
self.assertTrue(np.allclose(res2, expected2))
示例2: test_nanfunctions_matrices_general
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nancumprod [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_nancumprod
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nancumprod [as 别名]
def test_nancumprod(self):
tgt = np.cumprod(self.mat)
for mat in self.integer_arrays():
assert_equal(np.nancumprod(mat), tgt)
示例4: test_result_values
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nancumprod [as 别名]
def test_result_values(self):
for axis in (-2, -1, 0, 1, None):
tgt = np.cumprod(_ndat_ones, axis=axis)
res = np.nancumprod(_ndat, axis=axis)
assert_almost_equal(res, tgt)
tgt = np.cumsum(_ndat_zeros,axis=axis)
res = np.nancumsum(_ndat, axis=axis)
assert_almost_equal(res, tgt)
示例5: test_nancumprod
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import nancumprod [as 别名]
def test_nancumprod(self):
with pytest.raises(u.UnitsError):
np.nancumprod(self.q)