python解离散数学_亚图跨际的博客-爱代码爱编程
离散数学
离散数学是对可数的、不同的或独立的数学结构的研究。 一个很好的例子是像素。 从手机到电脑显示器再到电视机,现代屏幕由数百万个称为像素的小点组成,这些点排列成网格。 每个像素根据设备的命令以指定的颜色亮起,但每个像素只能显示有限数量的颜色。
数以百万计的彩色圆点组合在一起形成错综复杂的图案,给我们的眼睛带来平滑曲线的形状印象,如以下圆圈的边界:
但是,如果您放大并足够仔细地观察,就会发现真正的“曲线”是不同颜色像素区域之间的锯齿状边界,可能带有一些中间颜色,如下图所示:
相比之下,许多可能更熟悉的数学领域,例如初等代数或微积分,都侧重于连续统。 这些是在连续范围内取值的数学对象,例如介于 0 和 1 之间的一组数字 x,或绘制为平滑曲线的数学函数。 这些对象带有它们自己的数学方法类,但与我们将关注的离散问题的方法大多不同。
在数学中,集合论是对对象集合的研究,是研究离散数学的必备知识。
形式逻辑和构造数学证明
形式逻辑和真值表证明,直接的数学证明,反证法,数学归纳法证明
基数计算
以 n 为底的数,基数之间的转换,二进制数及其应用,布尔代数,十六进制数及其应用
Scipy 数学库
离散概率的元素
离散概率的基础,条件概率和贝叶斯定理,贝叶斯垃圾邮件过滤,随机变量、均值和方差,谷歌 PageRank I
线性代数计算算法
理解线性方程组,线性系统的矩阵和矩阵表示,用高斯消元法求解小型线性系统,使用 NumPy 求解大型线性系统
算法需求计算
算法的计算复杂度,具有基本控制结构的算法的复杂性,常见搜索算法的复杂性,常见搜索算法的复杂性
#Type of algorithm - inserting new element to pre-existing list
fruit_name = ["Jackfruit", "Honeydew", "Grapes"]
user_input1 = input("Please enter a fruit name: ")
fruit_name.append(user_input1)
print('The updated list is: ' + str(fruit_name))
#Type of algorithm - deleting element from list
user_input2 = input("Please enter the name of the fruit you
want to delete: ")
fruit_name.remove(user_input2)
print('The updated list is: ' + str(fruit_name))
Please enter a fruit name: Apple
The updated list is: ['Jackfruit', 'Honeydew', 'Grapes',
'Apple']
Please enter the name of the fruit you want to delete: Apple
The updated list is: ['Jackfruit', 'Honeydew', 'Grapes']
Process finished with exit code 0
显示算法运行所用的时间:
# a is a list containing some numbers
#We will compare the number input by user with the numbers in
# this list
import timeit
tic=timeit.default_timer()
a=[1,2,3,4,5,6,7,8]
INPUT = input("Please input a number of your choice: ")
number = int(INPUT)
for i in range(len(a)):
if a[i]== number:
print("Yes", end=' ')
else:
print("No", end=' ')
print()
toc=timeit.default_timer()
time_elapsed = toc - tic
print("The time elapsed for this computation is: " + str(time_
elapsed) + "seconds")
Please input a number of your choice: 1
Yes No No No No No No No
The time elapsed for this computation is: 2.3035541 seconds
Process finished with exit code 0