本文整理匯總了Python中numpy.nancumsum方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.nancumsum方法的具體用法?Python numpy.nancumsum怎麽用?Python numpy.nancumsum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.nancumsum方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testNanCumReduction
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import nancumsum [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 nancumsum [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_nancumsum
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import nancumsum [as 別名]
def test_nancumsum(self):
tgt = np.cumsum(self.mat)
for mat in self.integer_arrays():
assert_equal(np.nancumsum(mat), tgt)
示例4: test_result_values
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import nancumsum [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_nancumsum
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import nancumsum [as 別名]
def test_nancumsum(self):
def ref_impl(a):
return np.nancumsum(a)
def sdc_impl(a):
return numpy_like.nancumsum(a)
self.check_reduction_basic(ref_impl, sdc_impl)
示例6: test_nancumsum
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import nancumsum [as 別名]
def test_nancumsum(self):
self.check(np.nancumsum)