def sum(self, name: str = "") -> Money:
     if name:
         return u.sum([
             u.parse_money(a["amount"]) for a in self
             if a["name"].startswith(name)
         ])
     return u.sum([u.parse_money(a["amount"]) for a in self])
Exemple #2
0
def polyR(s, p):
    """
    :param s: ``Signal``
    :param p: ``poly.Polynomial``
    :return: New signal that is ``s`` transformed by ``p`` interpreted
     as a polynomial in *R*.
    """
    # range(10, -1, -1) counts down from 10 to 0, inclusive
    return util.sum([c * Rn(s, k) \
                 for (c, k) in zip(p.coeffs, range(p.order, -1, -1))])
Exemple #3
0
def polyR(s, p):
    """
    @param s: C{Signal}
    @param p: C{poly.Polynomial}
    @return: New signal that is C{s} transformed by C{p} interpreted
    as a polynomial in I{R}.
    """
    # range(10, -1, -1) counts down from 10 to 0, inclusive
    return util.sum([c * Rn(s, k) \
                 for (c, k) in zip(p.coeffs, range(p.order, -1, -1))])
Exemple #4
0
def polyR(s, p):
    """
    :param s: ``Signal``
    :param p: ``poly.Polynomial``
    :return: New signal that is ``s`` transformed by ``p`` interpreted
     as a polynomial in *R*.
    """
    # range(10, -1, -1) counts down from 10 to 0, inclusive
    return util.sum([c * Rn(s, k) \
                 for (c, k) in zip(p.coeffs, range(p.order, -1, -1))])
Exemple #5
0
def polyR(s, p):
    """
    @param s: C{Signal}
    @param p: C{poly.Polynomial}
    @return: New signal that is C{s} transformed by C{p} interpreted
    as a polynomial in I{R}.
    """
    # range(10, -1, -1) counts down from 10 to 0, inclusive
    return util.sum([c * Rn(s, k) \
                 for (c, k) in zip(p.coeffs, range(p.order, -1, -1))])
Exemple #6
0
def test_closure_lambda():
    print('[py/closure]')

    sumFunc = util.sum()
    box = [1, 2, 3, 4, 5, 6]
    for val in box:
        print(sumFunc(val), end=' ')
    print()

    print('[py/lambda]')

    # lambda返回的值作为该元素的权值,sort将按照权值大小进行排序
    # 奇数为False,偶数为True,故奇数在前
    print(sorted(box, key=lambda x: x % 2 == 0))
Exemple #7
0
    def getRect(self, x, y):
        X, Y, space = self.X, self.Y, self.space

        if type(X) == int:
            width = float(self.width) / X
            xp = self.x + width * x
        elif [list, tuple].__contains__(type(X)):
            width = float(self.width) * X[x] / sum(X)
            xp = self.x + float(self.width) * sum(X, 0, x)/sum(X)

        if type(Y) == int:
            height = float(self.height) / Y
            yp = self.y + height * y
        elif [list, tuple].__contains__(type(Y)):
            height = float(self.height) * Y[y] / sum(Y)
            yp = self.y + float(self.height) * sum(Y, 0, y)/sum(Y)

        rect = Rectangle((xp + space / 2.0, yp + space / 2.0, width - space, height - space))
        return rect
import util
from my_util import util2  #my_utin is package or folder
#util, util2 is module or a file

from my_util.util2 import squre as squre_x

print(util.sum(1, 2))
#3

print(util2.squre(2))
#4

print(squre_x(3))
#9

#pip install ....
#pip uninstall ...
#to install package of modules
Exemple #9
0
def softmax(x):
    exp = sp.exp(x - sp.max(x))
    return exp / sp.sum(exp, axis=1, keepdims=True)
Exemple #10
0
def pi_sum(a, b):
    return sum(lambda x: 1.0 / (x * (x + 2)), a, lambda x: x + 4, b)
Exemple #11
0
def integral(f, a, b, dx):
    return sum(f, a + dx / 2.0, lambda x: x + dx, b) * dx