《深刻 Python 3.0》 以及 IBM 開發社區的博客探索 Python .html
>>>S = {2, 3, 4, 5, 6, 7} >>>s = {x for x in S if x%2==0} # 偶數子集 >>>s set([2, 4, 6])
>>> import string >>> table = string.maketrans("abcdefghijklmnopqrstuvwxyz", "cdefghijklmnopqrstuvwxyzab") # 向後平移兩位 >>> print "hello".translate(table) jgnnq
>>> 1 + 1j (1+1j) >>> 1 + 1j + (10 + 20j) # 相加 (11+21j) >>> x = 1 + 3j >>> (x - 1)**2 # 相乘 (-9+0j) >>> x.real # 實部 1.0 >>> x.imag # 虛部 3.0 >>> type(x) <type 'complex'>
複數的絕對值python
>>> abs(3 + 4j)
5.0
複數畫點ide
plotting.py 的下載地址編碼
>>> from plotting import plot >>> L = [2+2j, 3+2j, 1.75+1j, 2+1j, 2.25+1j, 2.5+1j, 2.75+1j, 3+1j, 3.25+1j] >>> plot(L)
畫圖以下:加密
複數畫圖spa
>>> from image import * >>> I = color2gray(file2image('./pic/01.png')) >>> row = len(I) # 垂直高度 >>> col = len(I[0]) # 水平長度 >>> M = [x + y*1j for x in range(col) for y in range(row) if I[row-y-1][x] < 120] >>> plot(M, max(row, col), 1) # 第二個參數便於座標系大小的自動調節, 第三個參數表示每一個像素顯示的大小
圖像平移code
(x + yi) to (a+x + (b+y)i) htm
>>> plot({z + (1+2j) for z in L})
圖像縮放blog
(x + yi) to (0.5x + 0.5yi) 教程
>>> plot([.5*z for z in M], max(row, col), 1)
中心對稱變換
(x + yi) to (-x - yi)
>>> plot({-z for z in L})
以座標軸爲中心旋轉 90 度
(x + yi) to (-y + xi)
the same as:
(x + yi) to i*(x + yi)
>>> plot({1j*z for z in L})
以座標軸爲中心任意旋轉和縮放
旋轉 45 度:
>>> from math import pi, e >>> plot([e**(pi*1j/4)*z for z in M], max(row, col), 1)
歐拉恆等式:
歐拉公式:
玩玩有限域(伽羅華域, galois field)
galois field 2 只有兩個元素: 0 和 1. 在這個域中,加法運算是異或操做,乘法運算是與操做。運算律好比分配律在這裏仍然適用。
>>> from GF2 import one >>> one + one 0 >>> one + 0 one >>> one * one one >>> one * 0 0 >>> one / one one
對於這樣一個加密系統:
機率均勻分佈,而且密文與明文是獨立的。
Network coding
Streaming video through network
a) 一個顧客木有問題
b) 兩個顧客發生衝突
c) 先編碼,再解碼,兩個發送端可同時發送到兩個接收端