Skip to content

Instantly share code, notes, and snippets.

Exposing raw C++ buffers as NumPy arrays using Pybind11

Sometimes you have to work with C++ libraries that use raw pointers and arrays that you need to have access to from python. Indeed, working with C styles arrays is sometimes considered bad practice but many people still do...

The solution here is for the C++ side to provide the raw memory address of the data buffer, and then use numpy's array interface mechanism to create an ndarray that uses this buffer.

This allows the user to view and change elements of the buffers with no copies in a way that is visible to both C++ and Python sides.

@abidrahmank
abidrahmank / imagenet1000_clsid_to_human.txt
Created March 15, 2017 19:06 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class id to human readable labels
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',