python基础知识

一.随机数的生成(都需要 import random )
1.用于生成一个指定范围内的随机浮点数。

print random.uniform(10,20)
print random.uniform(20,10)

2.生成一个指定范围内的整数。(下限必须小于上限制)

 print random.randint(12,20)
 print random.randint(20,20)

3.随机选取0到100之间的偶数

print random.randrange(0,99)

4.随机浮点数

 print random.random()
 print random.uniform(1,10)

5.随机字符串

 print random.choice('abcdefg&#%^*f')

6.多个字符串中选取特定的字符串

print random.sample('abcdefghij',3) 
['a', 'd', 'b']

7.洗牌

 items = [1, 2, 3, 4, 5, 6]
 random.shuffle(items)
 items
[3, 2, 5, 6, 4, 1]

Numpy是python的一个科学计算库,提供了矩阵运算的功能,其一般与scipy, matplotlib一起使用。

8.数组的合并

 import numpy as np
 a = np.ones((2,2))
 b = np.eye(2)
 print np.vstack((a,b));
 [[ 1.  1.]
 [ 1.  1.]
 [ 1.  0.]
 [ 0.  1.]]
print np.hstack((a,b))
[[ 1.  1.  1.  0.]
 [ 1.  1.  0.  1.]]

.待续。。。。。。。