1. 程式人生 > >CS231n(一):基礎知識

CS231n(一):基礎知識

深度學習 highlight 自己 元組 .py [0 upper bsp python

給自己新挖個坑:開始刷cs231n深度學習。

看了一下導言的pdf,差缺補漏。

s = "hello"
print s.capitalize()  # 首字母大寫; prints "Hello"
print s.upper()       # 全部大寫; prints "HELLO"
print s.rjust(7)      #空格; prints "  hello"
print s.center(7)     # 居中; prints " hello "
print s.replace(l, (ell))  # 替換;
                               # prints 
"he(ell)(ell)o" print world .strip() # Strip leading and trailing whitespace; prints "world"

切片和索引

nums = range(5)    # 生成[0,1,2,3,4]
print nums  
print nums[:]      # 全部輸出; prints "[0, 1, 2, 3, 4]"
print nums[:-1]    # 倒數第一個直接用-1; prints "[0, 1, 2, 3]"

元組

d = {(x, x + 1): x for x in range(10)}  #創建元組型字典
t = (5, 6)       # 創建元組
print type(t)    # Prints "<type ‘tuple‘>"
print d[t]       # Prints "5"
print d[(1, 2)]  # Prints "1"

創建空array

v = np.array([1, 0, 1])
y = np.empty_like(v)   # [0,0,0]
v = np.array([1, 0, 1])
vv = np.tile(v, (4, 1))  # [1,0,1]
                  [1,0,1]
                  [1,0,1]
                  [1,0,1]

矩陣轉置

a = np.array([[1,2,3],[4,5,6]])
b = a.T#輸出a的轉置

plt

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 3 * np.pi, 0.1) y = np.sin(x) plt.plot(x, y) plt.show()

subplot

import numpy as np
import matplotlib.pyplot as plt

# Compute the x and y coordinates for points on sine and cosine curves
x = np.arange(0, 3 * np.pi, 0.1)
y_sin = np.sin(x)
y_cos = np.cos(x)


plt.subplot(2, 1, 1)


plt.plot(x, y_sin)
plt.title(‘Sine‘)

plt.subplot(2, 1, 2)
plt.plot(x, y_cos)
plt.title(‘Cosine‘)


plt.show()

以上

:)

CS231n(一):基礎知識