没有合适的资源?快使用搜索试试~ 我知道了~
首页cs231n课堂笔记翻译pdf版本(全部)
资源详情
资源评论
资源推荐

CS231n
课
程笔
记
翻
译
:
Python Numpy
教
程
译
者
注
:
本
文
智
能
单
元
首
发
,
翻
译
自
斯
坦
福
CS231n
课
程笔
记
Python Numpy Tutorial
,
由
课
程
教
师
Andrej Karpathy
授
权
进
行
翻
译
。
本
篇
教
程
由
杜
客
翻
译
完
成
,
Flood Sung
、
SunisDown
、
巩子
嘉
和
一
位
不
愿
透
露
ID
的知
友
对
本
翻
译
亦
有
贡
献
。
原
文
如
下
这
篇
教
程
由
Justin Johnson
创
作
。
我
们
将
使
用
Python
编
程
语言
来
完
成
本
课
程
的
所
有
作
业
。
Python
是
一
门
伟
大
的
通
用
编
程
语言
,
在
一
些
常
用
库
(
numpy, scipy, matplotlib
)
的
帮
助
下,
它
又
会
变
成
一个
强
大
的
科
学
计
算
环
境
。
我
们
期望
你们中
大多
数
人
对
于
Python
语言
和
Numpy
库
比
较
熟
悉
,
而
对
于
没
有
Python
经
验
的
同
学
,
这
篇
教
程
可
以
帮
助
你们
快
速
了
解
Python
编
程
环
境
和
如
何使
用
Python
作为
科
学
计
算
工
具
。
一
部
分
同
学对
于
Matlab
有
一
定
经
验
。
对
于
这部
分
同
学
,
我
们
推
荐
阅
读
numpy for Matlab users
页面
。
你们
还
可
以
查
看
本
教
程
的
IPython notebook
版
。
该
教
程
是
由
Volodymyr Kuleshov
和
Isaac
Caswell
为
课
程
CS 228
创
建
的
。
内
容
列
表
:
Python
基
本
数据
类
型
容
器
列
表
字
典
杜
客
10
个
月
前

集
合
元
组
函
数
类
Numpy
数
组
访
问
数
组
数据
类
型
数
组
计
算
广
播
SciPy
图
像
操
作
MATLAB
文
件
点
之
间
的
距
离
Matplotlib
绘
制
图
形
绘
制
多
个
图
形
图
像
Python
Python
是
一
种
高
级
的
,
动
态
类
型
的
多
范
型
编
程
语言
。
很
多
时
候
,
大
家
会
说
Python
看
起
来
简
直
和
伪代
码
一
样
,
这
是
因
为你
能
够
通过
很
少
行
数
的
代
码
表
达
出
很
有
力
的
思
想
。
举
个
例
子
,下
面
是
用
Python
实
现
的
经
典
的
quicksort
算
法
例
子
:
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) / 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)

print quicksort([3,6,8,10,1,2,1])
# Prints "[1, 1, 2, 3, 6, 8, 10]"
Python
版
本
Python
有
两个
支
持
的
版
本
,
分别
是
2.7
和
3.4
。
这
有
点
让
人
迷
惑
,
3.0
向
语言
中
引
入
了
很
多
不
向后
兼
容
的
变
化
,
2.7
下
的
代
码
有时
候
在
3.4
下
是
行
不
通
的
。
在
这
个
课
程
中
,
我
们使
用
的
是
2.7
版
本
。
如
何
查
看
版
本
呢
?
使
用
python --version
命
令
。
基
本
数据
类
型
和
大多
数
编
程
语言
一
样
,
Python
拥
有
一
系
列
的
基
本
数据
类
型
,
比
如
整
型
、
浮
点
型
、
布尔
型
和
字
符
串
等
。
这
些
类
型
的
使
用
方
式
和
在
其
他
语言
中
的
使
用
方
式
是
类
似
的
。
数
字
:
整
型
和
浮
点
型
的
使
用
与
其
他
语言
类
似
。
x = 3
print type(x) # Prints "<type 'int'>"
print x # Prints "3"
print x + 1 # Addition; prints "4"
print x - 1 # Subtraction; prints "2"
print x * 2 # Multiplication; prints "6"
print x ** 2 # Exponentiation; prints "9"
x += 1
print x # Prints "4"
x *= 2
print x # Prints "8"
y = 2.5
print type(y) # Prints "<type 'float'>"
print y, y + 1, y * 2, y ** 2 # Prints "2.5 3.5 5.0 6.25"
需
要
注
意
的
是
,
Python
中
没
有
x++
和
x--
的
操
作
符
。
Python
也
有
内
置
的
长
整
型
和
复
杂
数
字
类
型
,
具
体
细
节
可
以
查
看
文
档
。
布尔
型
:
Python
实
现
了
所
有
的
布尔
逻辑
,
但
用
的
是
英
语
,
而
不
是
我
们习
惯
的
操
作
符
(
比
如
&&
和
||
等
)
。
t = True
f = False
print type(t) # Prints "<type 'bool'>"
print t and f # Logical AND; prints "False"

print t or f # Logical OR; prints "True"
print not t # Logical NOT; prints "False"
print t != f # Logical XOR; prints "True"
字
符
串
:
Python
对字
符
串
的
支
持
非
常
棒
。
hello = 'hello' # String literals can use single quotes
world = "world" # or double quotes; it does not matter.
print hello # Prints "hello"
print len(hello) # String length; prints "5"
hw = hello + ' ' + world # String concatenation
print hw # prints "hello world"
hw12 = '%s %s %d' % (hello, world, 12) # sprintf style string formatting
print hw12 # prints "hello world 12"
字
符
串
对
象
有
一
系
列
有
用
的
方
法
,
比
如
:
如
果
想
详
细
查
看
字
符
串
方
法
,
请
看
文
档
。
容
器
Containers
译
者
注
:
有
知
友
建
议
container
翻
译
为
复
合
数据
类
型
,
供
读
者
参
考
。
Python
有
以
下
几
种
容
器
类
型
:
列
表
(
lists
)
、
字
典
(
dictionaries
)
、
集
合
(
sets
)
和
元
组
(
tuples
)
。
列
表
Lists
列
表
就
是
Python
中
的
数
组
,
但
是
列
表
长
度
可变
,且
能
包
含
不
同
类
型
元
素
。
s = "hello"
print s.capitalize() # Capitalize a string; prints "Hello"
print s.upper() # Convert a string to uppercase; prints "HELLO"
print s.rjust(7) # Right-justify a string, padding with spaces; prints " hello"
print s.center(7) # Center a string, padding with spaces; prints " hello "
print s.replace('l', '(ell)') # Replace all instances of one substring with another;
# prints "he(ell)(ell)o"
print ' world '.strip() # Strip leading and trailing whitespace; prints "world"
xs = [3, 1, 2] # Create a list
print xs, xs[2] # Prints "[3, 1, 2] 2"
print xs[-1] # Negative indices count from the end of the list; prints "2"
xs[2] = 'foo' # Lists can contain elements of different types
print xs # Prints "[3, 1, 'foo']"

列
表
的
细
节
,
同
样
可
以
查
阅
文
档
。
切
片
Slicing
:
为了
一
次
性
地
获
取
列
表
中
的
元
素
,
Python
提
供了
一
种简
洁
的
语
法
,
这
就
是
切
片
。
在
Numpy
数
组
的
内
容
中
,
我
们会
再
次
看
到切
片
语
法
。
循
环
Loops
:
我
们
可
以
这
样
遍
历
列
表
中
的
每
一个
元
素
:
animals = ['cat', 'dog', 'monkey']
for animal in animals:
print animal
# Prints "cat", "dog", "monkey", each on its own line.
如
果
想
要
在
循
环
体
内
访
问
每
个
元
素
的
指
针
,
可
以使
用
内
置
的
enumerate
函
数
animals = ['cat', 'dog', 'monkey']
for idx, animal in enumerate(animals):
print '#%d: %s' % (idx + 1, animal)
# Prints "#1: cat", "#2: dog", "#3: monkey", each on its own line
列
表
推
导
List comprehensions
:
在
编
程
的
时
候
,
我
们
常常
想
要
将
一
种
数据
类
型
转
换
为
另
一
种
。
下
面
是
一个
简
单
例
子
,
将
列
表
中
的
每
个
元
素
变
成
它
的
平
方
。
nums = [0, 1, 2, 3, 4]
squares = []
for x in nums:
squares.append(x ** 2)
print squares # Prints [0, 1, 4, 9, 16]
使
用
列
表
推
导
,
你
就
可
以
让
代
码
简
化
很
多
:
xs.append('bar') # Add a new element to the end of the list
print xs # Prints
x = xs.pop() # Remove and return the last element of the list
print x, xs # Prints "bar [3, 1, 'foo']"
nums = range(5) # range is a built-in function that creates a list of integers
print nums # Prints "[0, 1, 2, 3, 4]"
print nums[2:4] # Get a slice from index 2 to 4 (exclusive); prints "[2, 3]"
print nums[2:] # Get a slice from index 2 to the end; prints "[2, 3, 4]"
print nums[:2] # Get a slice from the start to index 2 (exclusive); prints "[0, 1]"
print nums[:] # Get a slice of the whole list; prints ["0, 1, 2, 3, 4]"
print nums[:-1] # Slice indices can be negative; prints ["0, 1, 2, 3]"
nums[2:4] = [8, 9] # Assign a new sublist to a slice
print nums # Prints "[0, 1, 8, 8, 4]"
剩余175页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论1