2023年9月5日星期二

Python Study - 01 - Basics

 

BigDL: A Distributed Deep Learning Framework for Big Data
LLM: Large Language Model
  • Pytorch https://pytorch.org/


Python Recursive Functions


def iterTest(low, high):
while low < high:
print (low)
low+=1

# iterTest(1,8)
# iterTest(1,10)
def recurTest(low, high):
if low < high:
print(low)
recurTest(low+1, high)

recurTest(1,8)
Generator Function
sample code
# *** Generator Function
def oddGen(n, m):
while n < m:
yield n
n += 2


# Build a list a odd numbers between n and m
def oddLst(n, m):
lst = []
while n < m:
lst.append(n)
n += 2
return lst


# the time to perform sum on iterator
t1 = time.time()
sum(oddGen(1, 10000000))
print("Time to sum an iterator: %f" % (time.time() - t1))

t1 = time.time()
sum(oddLst(1, 10000000))
print("time to sum a list: %f" % (time.time() - t1))
# The generator function (yield) is much faster than list operations.
Else
sample code