- 多维数组操作
多维数组创建
>>> np.arange(0, 60, 10).reshape(-1, 1) + np.arange(0, 6)
array([[ 0, 1, 2, 3, 4, 5],
[10, 11, 12, 13, 14, 15],
[20, 21, 22, 23, 24, 25],
[30, 31, 32, 33, 34, 35],
[40, 41, 42, 43, 44, 45],
[50, 51, 52, 53, 54, 55]])
- 利用heapq求解最小n个元素的index
#coding=utf-8
#author='HL'
import numpy as np
import heapq
a = np.array([1,3,2,4,5,6,3])
'''help(heapq.nsmallest)
nsmallest(n, iterable, key=None)
Find the n smallest elements in a dataset.
Equivalent to: sorted(iterable, key=key)[:n]
None
'''
print heapq.nsmallest(3,range(len(a)),a.take)