コード例 #1
0
    def testSums(self):
        print 'test sum'
        ds = np.arange(12).reshape((3, 4))
        self.assertEquals(ds.sum(), 66)
        self.assertEquals(np.sum(ds), 66)
        self.checkitems([12, 15, 18, 21], ds.sum(0))
        self.checkitems([12, 15, 18, 21], ds.sum(-2))
        self.checkitems([12, 15, 18, 21], np.sum(ds, 0))
        self.checkitems([12, 15, 18, 21], np.sum(ds, -2))
        self.checkitems([6, 22, 38], ds.sum(1))
        self.checkitems([6, 22, 38], ds.sum(-1))
        self.checkitems([6, 22, 38], np.sum(ds, 1))
        self.checkitems([6, 22, 38], np.sum(ds, -1))
        lds = np.arange(1024 * 1024, dtype=np.int32)
        self.assertEquals(np.sum(lds, dtype=np.int32), -524288)
        self.assertEquals(np.sum(lds, dtype=np.int64), 549755289600)

        print 'test cumsum'
        self.checkitems([0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66],
                        np.cumsum(ds))
        self.checkitems([[0, 1, 2, 3], [4, 6, 8, 10], [12, 15, 18, 21]],
                        np.cumsum(ds, 0))
        self.checkitems([[0, 1, 3, 6], [4, 9, 15, 22], [8, 17, 27, 38]],
                        np.cumsum(ds, 1))
        self.checkitems([[0, 1, 3, 6], [4, 9, 15, 22], [8, 17, 27, 38]],
                        np.cumsum(ds, -1))
コード例 #2
0
 def testSums(self):
     print 'test sum'
     ds = np.arange(12).reshape((3,4))
     self.assertEquals(np.sum(ds), 66)
     self.checkitems([12, 15, 18, 21], np.sum(ds, 0))
     self.checkitems([ 6, 22, 38], np.sum(ds, 1))
     
     print 'test cumsum'
     self.checkitems([0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66], np.cumsum(ds))
     self.checkitems([[0, 1, 2, 3], [4, 6, 8, 10], [12, 15, 18, 21]], np.cumsum(ds, 0))
     self.checkitems([[0, 1, 3, 6], [4, 9, 15, 22], [8, 17, 27, 38]], np.cumsum(ds, 1))
コード例 #3
0
ファイル: dataset_test.py プロジェクト: erwindl0/scisoft-core
    def testSums(self):
        print 'test sum'
        ds = np.arange(12).reshape((3,4))
        self.assertEquals(np.sum(ds), 66)
        self.checkitems([12, 15, 18, 21], np.sum(ds, 0))
        self.checkitems([ 6, 22, 38], np.sum(ds, 1))
        lds = np.arange(1024*1024, dtype=np.int32)
        self.assertEquals(np.sum(lds, dtype=np.int32), -524288)
        self.assertEquals(np.sum(lds, dtype=np.int64), 549755289600)

        print 'test cumsum'
        self.checkitems([0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66], np.cumsum(ds))
        self.checkitems([[0, 1, 2, 3], [4, 6, 8, 10], [12, 15, 18, 21]], np.cumsum(ds, 0))
        self.checkitems([[0, 1, 3, 6], [4, 9, 15, 22], [8, 17, 27, 38]], np.cumsum(ds, 1))