python基础练习

1.随机数(0-100)产生:

import random
print int(random.random()*100)

2.numpy包中常用的函数:

shape函数返回数组每一个维度的长度

#用法
a.shape
a.shape[0]
a.shape[1]

 tile()主要用于数组的重复,生成新数组

#原来数组
a=[0.8,0.59]
#执行
print tile(a,(5,4=3))
#输出
[[0.8  0.59 0.8  0.59 0.8  0.59]
 [0.8  0.59 0.8  0.59 0.8  0.59]
 [0.8  0.59 0.8  0.59 0.8  0.59]
 [0.8  0.59 0.8  0.59 0.8  0.59]
 [0.8  0.59 0.8  0.59 0.8  0.59]]

sum(a,axis=0)或者是.sum(axis=1) 

c = array([[0, 2, 1], [3, 5, 6], [0, 1, 1]])

print c.sum()
print c.sum(axis=0)
print c.sum(axis=1)

#结果分别是:19, [3 8 8], [ 3 14  2]

原文地址:https://www.cnblogs.com/students/p/8808233.html