Python人工智能基础第一课

1.人工智能核心在于"学习",如何让计算机具备学习的能力。

2.人工智能分类:(1)统计(2)仿生

3.开发环境:(1)Anaconda(python发行版本,内部集成大量开发AI所需的框架)

(2)Pytorch(深度学习框架)

(3)PyCharm(IDE集成开发工具)

4.和电脑交流(编程语言)

python语言

(1)用python和电脑打招呼

Python3入门人工智能源码 python 人工智能入门_python


Python3入门人工智能源码 python 人工智能入门_Python3入门人工智能源码_02

变量:可以被改变的量

常量(数据):不能被改变的量叫做常量

变量是用来表示(存储)常量的

Python3入门人工智能源码 python 人工智能入门_Python3入门人工智能源码_03


使用变量是为了使用其内部的常量的。

因此,定义变量一定要给变量赋值,这个变量才有意义。

定义格式:变量名 = 初始化值

Python3入门人工智能源码 python 人工智能入门_Python3入门人工智能源码_04


Python3入门人工智能源码 python 人工智能入门_实训_05


数据类型:

a.数字:int(整数)

Python3入门人工智能源码 python 人工智能入门_学习_06


Python3入门人工智能源码 python 人工智能入门_实训_07


float(小数)

Python3入门人工智能源码 python 人工智能入门_实训_08


Python3入门人工智能源码 python 人工智能入门_python_09


b.字符串

Python3入门人工智能源码 python 人工智能入门_实训_10


Python3入门人工智能源码 python 人工智能入门_Python3入门人工智能源码_11


c.元组

Python3入门人工智能源码 python 人工智能入门_python_12


Python3入门人工智能源码 python 人工智能入门_python_13

d.列表

Python3入门人工智能源码 python 人工智能入门_实训_14


Python3入门人工智能源码 python 人工智能入门_Python3入门人工智能源码_15


e.字典

Python3入门人工智能源码 python 人工智能入门_学习_16


Python3入门人工智能源码 python 人工智能入门_Python3入门人工智能源码_17


f.集合Set()

Python3入门人工智能源码 python 人工智能入门_python_18


Python3入门人工智能源码 python 人工智能入门_实训_19


Python3入门人工智能源码 python 人工智能入门_python_20


Python3入门人工智能源码 python 人工智能入门_学习_21


(2)python语句

循环while

Python3入门人工智能源码 python 人工智能入门_实训_22


Python3入门人工智能源码 python 人工智能入门_实训_23


循环for

打印九九乘法表

for i in range(1,10):
    for j in range(1,i+1):
        print(str(j)+"*"+str(i)+'='+str(i*j)+";",end='')
    print()

Python3入门人工智能源码 python 人工智能入门_python_24

循环判断语句
food="肉"
if food == "面":
    print("吃面")
elif food == "饭":
    print("吃饭")
elif food == "肉":
    print("吃肉")
else:
    print("没得吃")

Python3入门人工智能源码 python 人工智能入门_实训_25

(3)函数代码块,用来封装功能的,提高代码的复用性
def tr(x,y):#定义函数
    for i in range(x):
        for j in range(y):
            print('*',end='')
        print()

tr(5,4)#调用函数

Python3入门人工智能源码 python 人工智能入门_python_26

(4)面向对象面向对象是一种编程思想。
class Car:
    def __init__(self):#构建函数,初始化对象
        self.color="红色"#属性
    def run(self):
        print("汽车开动啦!")

car1=Car()
car1.color = "黑色"
print(car1.color)
car1.run()
c2=Car()
print(c2.color)

Python3入门人工智能源码 python 人工智能入门_Python3入门人工智能源码_27


面向对象:关注的焦点是对象。

对象:真实存在的事物。

对象:属性(形容词,描述对象本身特性)(变量),

功能(动词,对象所具备的能力)(函数)

面向对象编程:找对象–》创建对象–》使用对象–》维护与对象之间的关系

类:类是用来描述对象的。图像的一个简单玩儿法

Python3入门人工智能源码 python 人工智能入门_python_28

from PIL import Image

img = Image.open('3.jpg')
img.show()

Python3入门人工智能源码 python 人工智能入门_实训_29


使用默认打开方式打开图片3.jpg

from PIL import Image, ImageFilter

# 读取图片
img = Image.open('3.jpg')
# #滤镜
# img = img.filter(ImageFilter.EMBOSS)
# #展示图象
# img.show()
# #存储图像
# img.save("test.jpg")
# 获取图像通道
bands = img.getbands()
# 灰度化 RGB--》L
# img = img.convert("L")
# print(bands)
# 获取图像的大小
s = img.size
print(s)
# 缩放
# w,h = img.size
# img.thumbnail((w//2,h//2))
# 旋转
# img = img.rotate(180)
# img.show()

# 重新定义大小
img = img.resize((300, 600))
img.show()

Python3入门人工智能源码 python 人工智能入门_Python3入门人工智能源码_30

from PIL import Image, ImageDraw, ImageFont, ImageFilter
import random


# 随机字母
def randChar():
    return chr(random.randint(65, 90))


# 随机颜色1
def randColor1():
    return (random.randint(65, 255),
            random.randint(65, 255),
            random.randint(65, 255))


# 随机颜色2
def randColor2():
    return (random.randint(0, 127),
            random.randint(0, 127),
            random.randint(0, 127))


# 240*60
width = 240
height = 60
image = Image.new("RGB", (width, height), (255, 255, 255))
# 创建Font对象
font = ImageFont.truetype("arial.ttf", 36)
# 创建Draw对象
draw = ImageDraw.Draw(image)
# 填充像素
for x in range(width):
    for y in range(height):
        draw.point((x, y), fill=randColor1())
# 输入文字
for i in range(4):
    draw.text((60 * i + 10, 10), randChar(), fill=randColor2(), font=font)
image = image.filter(ImageFilter.BLUR)
image.show()

产生一个随机“验证码”

Python3入门人工智能源码 python 人工智能入门_Image_31