斋藤康毅-深度学习入门 学习笔记一

这篇博客介绍了Python的基础知识,包括版本查询、算术运算、类型判断、列表操作和字典使用。进一步展示了类的定义及方法调用。此外,还探讨了matplotlib和numpy库,用于绘制图形和处理多维数组。通过实例演示了如何读取图片和进行数值计算。
摘要由CSDN通过智能技术生成

ch01 Python入门

  1. basic.py
'''
python --version

note in python3  5/2 = 2.5

4**2 = 16

type(3.4)

x = 10 then x = "123"  it's ok in python

list
x = [1, 2, 3, 4, 5]
print(x)
len(x)
x[1]
x[1:3]
x[:4]
x[3:]
x[:-3]

dictionary
dict = {"name" : "raymond"}
dict["name"]

for i in [1, 2, 3]:
    print(i)
'''
  1. hungry.py
print("I am hungry")

# python ./hungry.py
  1. man.py
class Man:
    def __init__(self, name):
        self.name = name
        print("Initialized!")

    def hello(self):
        print("Hello " + self.name + "!")

    def goodbye(self):
        print("good-bye " + self.name + "!")

m = Man("raymond")
m.hello()
m.goodbye()
  1. matplotlib1.py
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import imread

x = np.arange(0, 6, 0.1)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y1, label="sin")
plt.plot(x, y2, linestyle="--", label="cos")
plt.xlabel("x")
plt.ylabel("y")
plt.title("sin & cos")
#  加上图例
plt.legend()
plt.show()

# read image
img = imread("pic.jpg")
plt.imshow(img)
plt.show()
  1. numpy1.py
'''
import numpy as np

x = np.array([1.0, 2.0, 3.0])
x
type(x)

y = np.array([2.0, 4.0, 6.0])
y

# the length should be the same
x + y
x - y
x * y
x / y

x / 3.0

x = np.array([[1, 2], [3, 4]])
x.shape
x.dtype

y = np.array([10, 20])
x * y

x[0]
x[1][0]

x = x.flatten()
x

x % 2 == 1
x[x % 2 == 1]
'''
  • python是一种简单易记的编程语言
  • python是开源的,可以自由使用
  • python有“解释器”和“脚本文件”两种运行模式
  • python能够将一系列的处理集成为函数或类等模块
  • numpy中有很多用于操作多维数组的便捷方法

斋藤康毅-深度学习入门 专栏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值