random.sample函数
从list中随机获取5个元素,作为一个片断返回
import random
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for i in range(2):
slice = random.sample(list, 5)
print(slice)
print(list, '\n')
结果:
[5,9,4,7,6]
[1,2,3,4,5,6,7,8,9,10]
[3,7,4,2,8]
[1,2,3,4,5,6,7,8,9,10]
numpy.reshape函数
新数组元素数量与原数组元素数量要相等。当一个参数为-1时,那么reshape函数会根据另一个参数的维度计算出数组的另外一个shape属性值。
numpy.amax函数
numpy.amax() 用于计算数组中的元素沿指定轴的最大值。
a = np.array([[3,7,5],[8,4,3],[2,4,9]])
print (np.amax(a, axis = 0))
print (np.amax(a))
结果:
[8 7 9]
9