/numpy2go

A simple example of passing a pointer to numpy array to go (golang) code.

Primary LanguagePythonBSD 2-Clause "Simplified" LicenseBSD-2-Clause

numpy2go

This is a simple example of how to write a go libary (shared object) with exported functions that can accept numpy arrays as passed by ctypes. It requires go 1.5.

To try it run:

go build -buildmode=c-shared -o numpy2go.so
python numpy2go.py

Which should output:

Python says [ 0.  1.  2.]
Go says [0 1 2]

The code is based on these two sources:

https://scipy-lectures.github.io/advanced/interfacing_with_c/interfacing_with_c.html#id5

https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices