Skip to content

Instantly share code, notes, and snippets.

@tomerfiliba
tomerfiliba / gist:3698403
Created September 11, 2012 13:20
get the indexes of the top n elements in a numpy 2d-array
import numpy as np
import bottleneck as bn
def top_n_indexes(arr, n):
idx = bn.argpartsort(arr, arr.size-n, axis=None)[-n:]
width = arr.shape[1]
return [divmod(i, width) for i in idx]
np.random.seed(47)
@tomerfiliba
tomerfiliba / gist:3773288
Created September 23, 2012 22:33
mumble
import threading
MAPPINGS = {
"&" : "&",
"'" : "'",
'"' : """,
"<" : "&lt;",
">" : "&gt;",
}
VlanTagOrType = Struct("VlanTagOrType",
Enum(UBInt16("type"),
IPv4 = 0x0800,
ARP = 0x0806,
RARP = 0x8035,
X25 = 0x0805,
IPX = 0x8137,
IPv6 = 0x86DD,
VLAN_TAG = 0x8100,
_default_ = Pass,
@tomerfiliba
tomerfiliba / construct++.cpp
Created February 25, 2014 19:54
Consturct++: Pickler combinators in C++11
#include <iostream>
#include <sstream>
#include <cstdint>
#include <cstddef>
#include <string>
#include <memory>
#include <vector>
#include <tuple>
#include <utility>
#include <type_traits>